oauth2设置token过期时间,oauth2设置刷新token过期时间
oauth2设置token过期时间,在配置中重写DefaultTokenServices
中默认的12小时即可:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public ClientDetailsService jdbcDetailsService(){
return new JdbcClientDetailsService(dataSource());
}
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource());
}
@Bean
@Primary
public DefaultTokenServices defaultTokenServices(){
DefaultTokenServices services=new DefaultTokenServices();
services.setAccessTokenValiditySeconds(20);//设置20秒过期
services.setRefreshTokenValiditySeconds(666);//设置刷新token的过期时间
services.setTokenStore(tokenStore());
return services;
}
@Autowired
private BCryptPasswordEncoder passwordEncoder;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(jdbcDetailsService());
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
//endpoints.tokenStore(tokenStore());
endpoints.tokenServices(defaultTokenServices());
}
}
网友评论