这是我的应用程序属性文件:
spring.security.oauth2.client.registration.myclient.client-id=SampleClientId
spring.security.oauth2.client.registration.myclient.client-secret=secret
spring.security.oauth2.client.provider.myclient.authorization-uri=http://localhost:8081/auth/oauth/authorize
spring.security.oauth2.client.provider.myclient.token-uri=http://localhost:8081/auth/oauth/token
spring.security.oauth2.client.provider.myclient.user-info-uri=http://localhost:8081/auth/user/me
spring.security.oauth2.client.registration.myclient.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.myclient.redirect-uri=http://localhost:8080/hellouser
spring.security.oauth2.client.provider.myclient.userNameAttribute=user
这是我的配置类:
@Configuration class SecurityConfig extends WebSecurityConfigurerAdapter {
@throws[Exception]
override protected def configure(http: HttpSecurity): Unit = {
http.authorizeRequests.anyRequest.authenticated.and.oauth2Login
.redirectionEndpoint()
.baseUri("/")
}
}
这是我的控制器:
case class Message(val string: String)
@Controller
class SuccessController {
@GetMapping(path = Array("/hellouser"), produces = Array(MediaType.APPLICATION_JSON_VALUE))
def getHelloUser(model: Model, authentication: OAuth2AuthenticationToken ): Message = {
Message("hello user")
}
}
登录后,我会返回 ERR_TOO_MANY_REDIRECTS
在开发者控制台的“网络”部分,我看到这三个调用被无限地重复:
我做错了什么?
谢谢
答案 0 :(得分:3)
请勿将重定向URI设置为API。
授权码流中的重定向URI用于拾取授权码,以便随后可以将其交换为令牌。
设置中发生的是
/helloworld
的请求https://auth0.com/docs/flows/concepts/auth-code对此有所了解,您没有进入步骤4,而是将流程短路回到步骤1
您的配置使auth代码流从未完成。您应该只保留Spring默认重定向URI并删除spring.security.oauth2.client.registration.myclient.redirect-uri=http://localhost:8080/hellouser
也不需要设置redirectionEndpoint#baseUri
配置。
编辑
另外的澄清是,使用Spring Security保存了第1步中的初始请求,并且当在第4步中完成授权代码流时,Spring会自动重播保存的请求。