首页 > 解决方案 > 如何在 keycloak 的 REST API 中使用身份提供者?

问题描述

我目前正在从我自己的“组合”身份验证系统切换到 keycloak。我目前在试图弄清楚如何使用身份提供者通过 keycloak 登录时遇到了一些困难。到目前为止,我能够使用其余 API 轻松添加身份提供者:http://localhost:8080/auth/admin/realms/test/users

{"firstName":"FIRSTNAME","lastName":"LASTNAME", "enabled":"true", "username":"app-user", "federatedIdentities": [{"identityProvider": "google", "userId": "XXXXXXXXXXXXXX", "userName": "XXXX XXXXXXXXXXXX"}]}

在进入管理面板并通过他们的网络界面登录后,一切似乎都正常了。

我目前正在尝试使用 REST API 登录,但我不断收到以下错误

{
    "error": "invalid_grant",
    "error_description": "Code not valid"
}

使用以下 URL 和参数

http://localhost:8080/auth/realms/test/protocol/openid-connect/token
clinet_id=test
grant_type=authorization_code
code=XXXX(pulled from frontend using react-social-login)
redirect_uri=http://localhost:8080/redirect
client_secret=XXXXXX

任何帮助将不胜感激,因为我希望能够使用 REST API 完成所有登录,如果您还建议切换到最适合我的应用程序的东西(从前端传递信息并在后端授权),请告诉我.

标签: reactjsrestoauthkeycloak

解决方案


推荐阅读