java - 尝试将 OneLogin OIDC 与 SpringBoot 一起使用时出错(错误:redirect_uri_mismatch)
问题描述
几天来,我一直在尝试将 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
在 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(仅 https)的重定向 URI,因此我需要在 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_uris 列表是正确的 https://localhost:8081/login?code=XX
是来自成功身份验证的正确响应,问题必须在于客户端处理响应的方式以及 html/login
期望在您的应用程序中呈现的内容- OneLogin 确实支持
http
,localhost
因此您不必弄乱 SSL
推荐阅读
- r - 为什么我在 as.factor() R 中会出现级别错误?
- sqlite - 如何使用 BLoC 模式执行 CRUD 操作?
- html - 在固定元素上滚动不适用于隐藏在 html 元素上的溢出
- haskell - Haskell - 使用列表元素压缩列表
- sql - 用于自定义基于 SQL 的 Web 搜索功能的倒排索引
- jenkins - 使用声明性管道(Jenkinsfile)在 Jenkins 中发布静态代码指标报告
- scala - 将字节反序列化为 GenericRecord / Row
- google-sheets - 麻烦的语法 - ArrayFormula + CONC + Filter
- angularjs - 在角度 7 中读取没有 HttpClient 的文本文件或 xml
- c# - Possibility to load video without extension from StreamingAssets?