java - spring boot oauth2 不要在 oauth_access_token 中插入值
问题描述
我想撤销用户的令牌。为此,我尝试检索应用程序的用户令牌列表。
我发现这个例子可以满足我的需要。
所以我开始使用 TokenStore 来存储我的令牌所以我的数据库中有这些新表(postgres):
CREATE TABLE oauth_access_token
(
token_id VARCHAR(255),
token bytea,
authentication_id VARCHAR(255),
user_name VARCHAR(255),
client_id VARCHAR(255),
authentication bytea,
refresh_token VARCHAR(255)
);
CREATE TABLE oauth_refresh_token
(
token_id VARCHAR(255),
token bytea,
authentication bytea
);
此表用于以下配置:
AuthServerOAuth2Config
@Configuration
@EnableAuthorizationServer
@FrameworkEndpoint
public class AuthServerOAuth2Config extends AuthorizationServerConfigurerAdapter {
private static final int ACCESS_TOKEN_VALIDITY_SECONDS = 2 * 60 * 60;
private static final int REFRESH_TOKEN_VALIDITY_SECONDS = 2 * ACCESS_TOKEN_VALIDITY_SECONDS;
@Value("${oauth.client-id}")
private String clientId;
@Value("${oauth.secret}")
private String clientSecret;
private final AuthenticationManager authenticationManager;
@Autowired
private Environment env;
@Autowired
private DataSource dataSource;
@Autowired
public AuthServerOAuth2Config(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
defaultTokenServices.setSupportRefreshToken(true);
return defaultTokenServices;
}
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource);
}
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(clientSecret);
return converter;
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer
.inMemory()
.withClient(clientId)
.secret(clientSecret)
.authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
.scopes("read", "write", "trust")
.accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS)
.refreshTokenValiditySeconds(REFRESH_TOKEN_VALIDITY_SECONDS);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
endpoints.authenticationManager(authenticationManager);
endpoints.tokenStore(tokenStore());
}
}
我的数据库的配置在应用程序的 .properties 文件中定义。我可以很好地访问我的桌子,但它们仍然是空的。
解决方案
推荐阅读
- r - 如何在 R 中将日期从 d/m/y 转换为 ymd
- java - 将用户插入用于 getter 时出现问题
- swift - 调用 URLSession 后我不能做其他工作
- azure - 他们是执行自定义 python 或任何语言的任何选项。作为 ARM 模板执行 immd 的一部分,新创建的 VM 上的脚本。虚拟机创建后?
- c++ - 流操纵器的自由函数与直接重载运算符<<
- pine-script - 短信号和长信号的数量
- amazon-web-services - 我想用 html 向用户展示来自 S3 的视频
- python - 我需要帮助我该如何摆脱这个?
- python - 如何在pygame中重复我的功能
- 2d-games - Godot 跳转动画在输入稍有延迟后开始