如何在 keycloak 中验证令牌并获取用户详细信息?

How can I verify token and get user details in keycloak?

我在我的 nodejs 应用程序中为 keycloak 上的注册用户实现了 keycloak,用于登录 API 我使用 API:

http://localhost:8080/auth/realms/master/protocol/openid-connect/token

如果用户名和密码正确,是return登录用户的令牌,

现在我需要传递这个令牌(return 上面 API)并检查这个令牌是否正确,如果令牌正确我需要用户详细信息,有没有 API为此。

提前致谢

Now I need to pass this token(return by above API) and check this token is correct or not

您将需要使用 Keycloak 文档中的 introspection endpoint

token_introspection_endpoint

A OAuth2-compliant Token Introspection Endpoint which clients can use to query the server to determine the active state of an RPT and to determine any other information associated with the token, such as the permissions granted by Keycloak.

and if token is correct I need user details, is there any API for this.

为此你需要使用 userinfo_endpoint

两个端点都可以在以下link下找到:

{KEYCLOAK_URL}/auth/realms/{REALM_NAME}/.well-known/openid-configuration