2022-05-29 15:45:56.492 INFO 20820 — [nio-8080-exec-9] o.s.s.o.p.e.AuthorizationEndpoint : Handling OAuth2 error: error=“invalid_grant”, error_description=“A redirect_uri can only be used by implicit or authorization_code grant types.”
在SpringSecurityOauth2整合SSO过程中
问题:
首先异常是
2022-05-29 15:45:56.492 INFO 20820 --- [nio-8080-exec-9] o.s.s.o.p.e.AuthorizationEndpoint : Handling OAuth2 error: error="invalid_grant", error_description="A redirect_uri can only be used by implicit or authorization_code grant types."
问题出现在授权服务的配置里的authorizedGrantTypes类型缺少authorization_code配置
解决:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
//配置clientid
.withClient("admin")
//配置clientsecret
.secret(passwordEncoder.encode("112233"))
//配置令牌的有效期
.accessTokenValiditySeconds(33600)
//配置刷新令牌的有效期
.refreshTokenValiditySeconds(8640000)
//用于授权成功后跳转
.redirectUris("http://localhost:8081/login")
//自动授权配置
.autoApprove(true)
.scopes("all")
//授权码模式 配置grant_type,表示授权类型
//.authorizedGrantTypes("authorization_code")
//在授权模式配置grant_type,表示授权类型是 授权码模式
.authorizedGrantTypes("password","refresh_token","authorization_code")
;
}