gpt4 book ai didi

java - InvalidGrantException,运行两个(或更多)Spring OAuth Server 时授权代码无效

转载 作者:行者123 更新时间:2023-11-29 02:59:52 25 4
gpt4 key购买 nike

那里有两个服务。我正在使用 Netflix 堆栈 [Eureka/zuul]。

  1. 聚合服务
  2. 用户服务 [Spring OAUTH]

当我运行一个用户服务实例时,一切正常,但是当我在另一台服务器上运行另一个实例时,出现下面提到的错误并且请求 [login oauth] 失败。

我想扩展使用 spring oauth 的 USER-SERVICE。

Handling error: InvalidGrantException, Invalid authorization code: Q1j7Hs 06:24:17.253 [http-nio-8081-exec-2] INFO o.s.s.o.p.e.TokenEndpoint - Handling error: InvalidGrantException, Invalid authorization code: w9uvl1

如有任何线索或建议,我们将不胜感激。

最佳答案

配置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());
}
}

并创建oauth_code表:

CREATE TABLE oauth_code (
code VARCHAR(256), authentication LONGVARBINARY
);

关于java - InvalidGrantException,运行两个(或更多)Spring OAuth Server 时授权代码无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35789741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com