Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.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 InvalidGrantException,运行两个(或多个)Spring OAuth服务器时的授权代码无效_Java_Spring_Spring Security_Oauth - Fatal编程技术网

Java InvalidGrantException,运行两个(或多个)Spring OAuth服务器时的授权代码无效

Java InvalidGrantException,运行两个(或多个)Spring OAuth服务器时的授权代码无效,java,spring,spring-security,oauth,Java,Spring,Spring Security,Oauth,有两种服务。我使用的是Netflix stack[Eureka/zuul] 聚合器服务 用户服务[Spring OAUTH] 当我运行一个用户服务实例时,一切正常,但当我在另一台服务器上运行另一个实例时,我遇到下面提到的错误,请求[login oauth]失败 我想扩展使用SpringOAuth的用户服务 处理错误:InvalidGrantException,授权代码无效: Q1j7Hs 06:24:17.253[http-nio-8081-exec-2]信息 o、 s.s.o.p.e.Toke

有两种服务。我使用的是Netflix stack[Eureka/zuul]

  • 聚合器服务
  • 用户服务[Spring OAUTH]
  • 当我运行一个用户服务实例时,一切正常,但当我在另一台服务器上运行另一个实例时,我遇到下面提到的错误,请求[login oauth]失败

    我想扩展使用SpringOAuth的用户服务

    处理错误:InvalidGrantException,授权代码无效: Q1j7Hs 06:24:17.253[http-nio-8081-exec-2]信息 o、 s.s.o.p.e.TokenEndpoint-处理错误:InvalidGrantException, 无效的授权代码:w9uvl1


    任何线索或建议都将不胜感激。

    如果您有两个实例,您必须小心,一个客户总是与同一实例交谈。否则,客户端可能会向实例A发出第一个请求,并进一步向实例B发出请求

    在这种情况下,客户端通常连接到转发到服务实例的负载平衡器

    您必须选择以下选项:

  • 将负载平衡器配置为始终将客户端连接到同一实例,这是通过粘性会话完成的
  • 让实例共享其会话,例如在reddis存储中 看这里

  • 如果您有两个实例,您必须小心,一个客户端总是与同一个实例对话。否则,客户端可能会向实例A发出第一个请求,并进一步向实例B发出请求

    在这种情况下,客户端通常连接到转发到服务实例的负载平衡器

    您必须选择以下选项:

  • 将负载平衡器配置为始终将客户端连接到同一实例,这是通过粘性会话完成的
  • 让实例共享其会话,例如在reddis存储中 看这里

  • 配置
    AuthorizationServerConfiguration
    以使用
    JdbcAuthorizationCodeServices
    服务在所有身份验证节点之间通过数据库存储和共享授权代码

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter implements EnvironmentAware {
    
        @Inject
        private DataSource dataSource;
    
        @Bean
        public TokenStore tokenStore() {
            return new JdbcTokenStore(dataSource);
        }
    
        // JdbcAuthorizationCodeServices stores authentication codes in a database.
        @Bean
        public JdbcAuthorizationCodeServices jdbcAuthorizationCodeServices() {
            return new JdbcAuthorizationCodeServices(dataSource);
        }
    
        @Inject
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;
    
        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints
                .tokenStore(tokenStore())
                .reuseRefreshTokens(false)
                .authenticationManager(authenticationManager)
                .authorizationCodeServices(jdbcAuthorizationCodeServices());
        }
    }
    
    并创建表:


    配置
    AuthorizationServerConfiguration
    以使用
    JdbcAuthorizationCodeServices
    服务在所有身份验证节点之间通过数据库存储和共享授权代码

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter implements EnvironmentAware {
    
        @Inject
        private DataSource dataSource;
    
        @Bean
        public TokenStore tokenStore() {
            return new JdbcTokenStore(dataSource);
        }
    
        // JdbcAuthorizationCodeServices stores authentication codes in a database.
        @Bean
        public JdbcAuthorizationCodeServices jdbcAuthorizationCodeServices() {
            return new JdbcAuthorizationCodeServices(dataSource);
        }
    
        @Inject
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;
    
        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints
                .tokenStore(tokenStore())
                .reuseRefreshTokens(false)
                .authenticationManager(authenticationManager)
                .authorizationCodeServices(jdbcAuthorizationCodeServices());
        }
    }
    
    并创建表:


    非常感谢。我们使用redis是因为我们无法使用粘性会话。谢谢。我们使用redis是因为我们无法使用粘性会话。