Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧靴;OAuth2.0:必须向客户端注册至少一个重定向uri_Java_Spring Boot_Oauth 2.0 - Fatal编程技术网

Java 弹簧靴;OAuth2.0:必须向客户端注册至少一个重定向uri

Java 弹簧靴;OAuth2.0:必须向客户端注册至少一个重定向uri,java,spring-boot,oauth-2.0,Java,Spring Boot,Oauth 2.0,因此,我登录到一个应用程序,然后转到一个外部功能,这要求再次登录(全部在应用程序内)。现在已经无法登录到该外部功能,因为它会抛出错误(代码400): 每当我使用应用程序或尝试直接登录到外部功能时,都会引发此错误 我在一个项目中将SpringBoot从1.4.1升级到了1.5.22,这可能是造成这种情况的原因。将弹簧靴降级至1.4.1后,问题消失了 然后,我尝试再次将Spring Boot更新为1.5.22,并在application.configuration中添加了以下内容: security

因此,我登录到一个应用程序,然后转到一个外部功能,这要求再次登录(全部在应用程序内)。现在已经无法登录到该外部功能,因为它会抛出错误(代码400):

每当我使用应用程序或尝试直接登录到外部功能时,都会引发此错误

我在一个项目中将SpringBoot从1.4.1升级到了1.5.22,这可能是造成这种情况的原因。将弹簧靴降级至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后,问题似乎消失了,但并不是很好的解决办法。

在验证之后,您可能需要联系资源所有者并请求支持,然后重定向到您的客户端应用程序,或者您可以直接重定向到客户端应用程序。 为此,请在授权服务器配置中添加
重定向URI

@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");
    }
}
@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");
    }
}