[英]Spring Boot & OAuth2.0: At least one redirect_uri must be registered with the client
所以我登录到一个应用程序并转到一个需要再次登录的外部功能(全部在应用程序内)。 现在无法登录该外部功能,因为它会引发错误(代码 400):
OAuth Error. error="invalid_request", error_description="At least one redirect_uri must be registered with the client."
每当我使用应用程序或尝试直接登录外部功能时,都会抛出此错误。
我已经将项目中的 Spring Boot 从 1.4.1 升级到 1.5.22,这可能是造成这种情况的原因。 将 Spring Boot 降级回 1.4.1 后,问题就消失了。
然后我再次尝试将 Spring Boot 更新到 1.5.22,并在 application.configuration 中额外包含了这个:
security.oauth2.client.pre-established-redirect-uri=https://page.com
security.oauth2.client.registered-redirect-uri=https://page.com
security.oauth2.client.use-current-uri=false
它没有帮助。 然后在浏览器的网络选项卡中,我注意到查询字符串参数中的 redirect_url 参数,它与我指定的参数不同。 它是这样的:
https://page.com/oauth-authorized/app
我更新了 application.configuration 如上所述。 然而,一切都没有改变。
如何进行?
一些代码:
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
private TokenStore tokenStore;
@Autowired
@Qualifier("clientDetailsServiceImpl")
private ClientDetailsService clientDetailsService;
@Autowired
private DefaultTokenServices tokenServices;
@Autowired
private TokenEnhancer tokenEnhancer;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.setClientDetailsService(clientDetailsService);
endpoints
.tokenStore(tokenStore)
.authenticationManager(authenticationManager)
.tokenServices(tokenServices)
.tokenEnhancer(tokenEnhancer)
.pathMapping("/oauth/token", "/api/oauth/token")
.pathMapping("/oauth/check_token", "/api/oauth/check_token")
.pathMapping("/oauth/authorize", "/api/oauth/authorize")
.pathMapping("/oauth/error", "/api/oauth/error");
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.checkTokenAccess("permitAll()");
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(clientDetailsService);
}
}
=================================================================================================
@Service
@Primary
public class ClientDetailsServiceImpl implements ClientDetailsService {
@Autowired
private ClientRepository clientRepository;
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
Client client = clientRepository.findOneByClientId(clientId)
.orElseThrow(() -> new NoSuchClientException(
String.format("Client with clientId=%s was not found", clientId)));
return new com.app.auth.domain.ClientDetails(client);
}
}
编辑:再次降级 Spring Boot 后,问题似乎消失了,但这并不是什么大问题。
身份验证后,您可能需要联系资源所有者并寻求支持,然后重定向到您的客户端应用程序,或者您可以直接重定向到客户端应用程序。 为此,在您的授权服务器配置中添加redirectUris
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter{
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("client_id").secret("client_secret").authorizedGrantTypes("authorization_code")
.scopes("read").authorities("CLIENT").redirectUris("http://localhost:8090/your_redirect_URL");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.