gpt4 book ai didi

java - 尝试将 OneLogin OIDC 与 SpringBoot 结合使用时出错(错误 : redirect_uri_mismatch)

转载 作者:行者123 更新时间:2023-12-01 21:58:17 25 4
gpt4 key购买 nike

我已经尝试将 OneLogin OIDC 与 SpringBoot 连接好几天了,但尚未成功。

我对 OIDC 还很陌生,所以,也许我错过了一些基本的东西。

我已按照 OpenLogin 管理面板中的以下说明进行操作: https://developers.onelogin.com/openid-connect/connect-to-onelogin

尝试了(主分支)中的代码: https://github.com/onelogin/onelogin-oidc-java/tree/master/spring-boot-app

并发现几天前在同一个存储库中有一个拉取请求,具有非常不同的解决方案(karson-demo-2019-oct 分支): https://github.com/onelogin/onelogin-oidc-java/tree/karson-demo-2019-oct/spring-boot-app

但不幸的是,该解决方案不起作用。

我使用的是 karson-demo-2019-oct 分支的相同代码,仅向 YAML 文件添加了一些属性(请参见下文)

我在 OneLogin 管理面板中将重定向 URI 配置为 https://localhost:8081/。当我转到 https://localhost:8081/ 时,单击“单击此处”,出现以下错误:

oops! something went wrong
error: redirect_uri_mismatch
error_description: redirect_uri did not match any client's registered redirect_uris
state: bi14wv

URL 类似于:

https://openid-connect.onelogin.com/oidc/auth?client_id=XXXXXXXXXXXXXXXXXXXXXX&redirect_uri=https://localhost:8081/login&response_type=code&scope=openid%20profile%20email&state=bi14wv

如果我将 https://localhost:8081/login (末尾带有“login”)添加到 OneLogin 管理面板中的重定向 URI 列表中,则会发生以下情况:当我转到 https://localhost:8081/ 并单击“单击此处”时,会出现 OneLogin 表单。然后我用我的用户登录,然后出现以下消息:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Nov 05 15:32:02 PST 2019
There was an unexpected error (type=Unauthorized, status=401).
Unauthorized

这个错误页面的 url 是这样的:

https://localhost:8081/login?code=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&state=ZZZZZ

正如您所看到的,在指定的重定向 URI (https://localhost:8081) 之后有一个“登录”,我认为这可能是由于 index.html 的方式造成的。已写在解决方案中。

由于 OneLogin 门户不接受带有 http 的重定向 URI(仅 https),因此我需要在 application.yml 中添加几行以启用 SSL:

security:
oauth2:
client:
clientId: XXXXXXXXXXXXXXXXXXXXXX
clientSecret: XXXXXXXXXXXXXXXXXXXXX
accessTokenUri: https://openid-connect.onelogin.com/oidc/token
userAuthorizationUri: https://openid-connect.onelogin.com/oidc/auth
tokenName: access_token
authorizedGrantTypes: authorization_code
authenticationScheme: form
clientAuthenticationScheme: form
scope: openid,profile,email
resource:
userInfoUri: https://openid-connect.onelogin.com/oidc/me

server:
port : 8081
ssl:
key-store-type: PKCS12
key-store: classpath:XXXXXXXXXXXX
key-store-password: XXXXXXXXXXXX
key-alias: XXXXXXXXXXX

这是正确的吗?你能帮我找出我缺少的东西吗?

最佳答案

一些事情:

  • 我不熟悉您正在运行的演示客户端,但看起来您是正确的,客户端生成的请求中的redirect_uri包含/login,并且您正确地将其添加到您的配置界面中的redirect_uri列表
  • https://localhost:8081/login?code=XX 是成功验证后的正确响应,问题一定出在客户端处理响应的方式以及 html /login 期望在您的应用中呈现
  • OneLogin 确实支持 localhosthttp,因此您不必搞乱 SSL

关于java - 尝试将 OneLogin OIDC 与 SpringBoot 结合使用时出错(错误 : redirect_uri_mismatch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58721643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com