Java InvalidGrantException,运行两个(或多个)Spring OAuth服务器时的授权代码无效
有两种服务。我使用的是Netflix stack[Eureka/zuul]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
任何线索或建议都将不胜感激。如果您有两个实例,您必须小心,一个客户总是与同一实例交谈。否则,客户端可能会向实例A发出第一个请求,并进一步向实例B发出请求 在这种情况下,客户端通常连接到转发到服务实例的负载平衡器 您必须选择以下选项:
如果您有两个实例,您必须小心,一个客户端总是与同一个实例对话。否则,客户端可能会向实例A发出第一个请求,并进一步向实例B发出请求 在这种情况下,客户端通常连接到转发到服务实例的负载平衡器 您必须选择以下选项:
配置
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是因为我们无法使用粘性会话。