提问者:小点点

无效参数“无效参数:redirect_uri” 密钥斗篷不关心我使用什么重定向 URI


我希望我的Spring Boot应用程序利用spring security和oath2功能,使用https://auth.mycompanytest.com/的a Keycloak服务器进行身份验证

我的初始尝试将用户发送到:

https://auth.mycompanytest.com/auth/realms/MycompanyProfiling/protocol/openid-connect/auth?response_type=code&client_id=my-app&state=3fleTCJg4dBwJNjAnbkuq9m2Lwfm7_KwcOsOvO5k2nM%3D&redirect_uri=%22http://localhost:8080/login/oauth2/code/keycloak%22

Keycloak然后说无效参数:redirect_uri

我已经尝试了这些东西redirect_uri:http://localhost:8080/* https://mycompanytest.com/*

但它不在乎。

application.properties片段:

spring.security.oauth2.client.registration.keycloak.client-id= ${KEYCLOAK_CLIENT_ID}
spring.security.oauth2.client.registration.keycloak.client-secret= ${KEYCLOAK_CLIENT_SECRET}
spring.security.oauth2.client.registration.keycloak.provider=keycloak
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.redirect-uri="{baseUrl}/login/oauth2/code/keycloak"
spring.security.oauth2.client.provider.keycloak.token-uri=http://localhost:8080/auth/realms/MyRealm/protocol/openid-connect/token
spring.security.oauth2.client.provider.keycloak.authorization-uri=https://auth.mycompanytest.com/auth/realms/MyRealm/protocol/openid-connect/auth
spring.security.oauth2.client.provider.keycloak.user-info-uri= http://localhost:8080/auth/realms/MyRealm/protocol/openid-connect/userinfo
spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username
spring.application.name=my-app
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8080/auth/realms/mycompany

*为了隐私和匿名,我用MyCompany、MyRealm、MyApp等代替了真实的应用程序*


共1个答案

匿名用户

请参阅redirect_uri参数:"http://localhost:8080/login/oauth2/code/keycloak"。它是URL编码值,因此解码值是"http://localhost:8080/login/oauth2/code/keycloak"-请注意,您在重定向URL中有",因此它无法匹配您在客户端配置中允许的值http://localhost:8080/*

我想问题是你的配置:

spring.security.oauth2.client.registration.keycloak.redirect-uri="{baseUrl}/login/oauth2/code/keycloak"

我会尝试:

spring.security.oauth2.client.registration.keycloak.redirect-uri={baseUrl}/login/oauth2/code/keycloak

OR

spring.security.oauth2.client.registration.keycloak.redirect-uri=http://localhost:8080/login/oauth2/code/keycloak

目标是从redirect_uri参数中删除引号()。