Java Code Examples for org.springframework.security.oauth2.provider.token.DefaultTokenServices#setReuseRefreshToken()
The following examples show how to use
org.springframework.security.oauth2.provider.token.DefaultTokenServices#setReuseRefreshToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SophiaAuthorizationServerConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 注意,自定义TokenServices的时候,需要设置@Primary,否则报错 */ @Primary @Bean public DefaultTokenServices defaultTokenServices() { DefaultTokenServices tokenServices = new DefaultTokenServices(); tokenServices.setTokenStore(tokenStore()); tokenServices.setSupportRefreshToken(true); // 这里如果设置为false则不能更新refresh_token,如果需要刷新token的功能需要设置成true tokenServices.setSupportRefreshToken(true); // 设置上次RefreshToken是否还可以使用 默认为true tokenServices.setReuseRefreshToken(false); // token有效期自定义设置,默认12小时 tokenServices.setAccessTokenValiditySeconds(60 * 60 * 6); // refresh_token默认30天 tokenServices.setRefreshTokenValiditySeconds(60 * 60 * 8); tokenServices.setTokenEnhancer(tokenEnhancer()); return tokenServices; }
Example 2
Source File: AuthorizationServerConfiguration.java From open-cloud with MIT License | 5 votes |
private DefaultTokenServices createDefaultTokenServices() { DefaultTokenServices tokenServices = new DefaultTokenServices(); tokenServices.setTokenStore(tokenStore()); tokenServices.setTokenEnhancer(tokenEnhancer()); tokenServices.setSupportRefreshToken(true); tokenServices.setReuseRefreshToken(true); tokenServices.setClientDetailsService(customClientDetailsService); return tokenServices; }
Example 3
Source File: AuthorizationServerConfiguration.java From open-cloud with MIT License | 5 votes |
private DefaultTokenServices createDefaultTokenServices() { DefaultTokenServices tokenServices = new DefaultTokenServices(); tokenServices.setTokenStore(tokenStore()); tokenServices.setTokenEnhancer(tokenEnhancer()); tokenServices.setSupportRefreshToken(true); tokenServices.setReuseRefreshToken(true); tokenServices.setClientDetailsService(customClientDetailsService); return tokenServices; }
Example 4
Source File: AuthorizationConfig.java From springcloud-oauth2 with MIT License | votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // 采用token转jwt,并添加一些自定义信息(token增强)(有默认非必须) TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); tokenEnhancerChain.setTokenEnhancers( Arrays.asList(jwtAccessTokenConverter(),tokenEnhancer())); endpoints.tokenEnhancer(tokenEnhancerChain) // 配置token存储,一般配置redis存储 .tokenStore(tokenStore()) // 配置认证管理器 .authenticationManager(authenticationManager) // 配置用户详情server,密码模式必须 .userDetailsService(userDetailsService) // 配置授权码模式授权码服务,不配置默认为内存模式 .authorizationCodeServices(authorizationCodeServices()) // 配置grant_type模式,如果不配置则默认使用密码模式、简化模式、验证码模式以及刷新token模式,如果配置了只使用配置中,默认配置失效 // 具体可以查询AuthorizationServerEndpointsConfigurer中的getDefaultTokenGranters方法 .tokenGranter(tokenGranter(endpoints)); // 配置TokenServices参数 DefaultTokenServices tokenServices = new DefaultTokenServices(); tokenServices.setTokenStore(endpoints.getTokenStore()); // 是否支持刷新Token tokenServices.setSupportRefreshToken(true); tokenServices.setReuseRefreshToken(true); tokenServices.setClientDetailsService(endpoints.getClientDetailsService()); tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer()); // 设置accessToken和refreshToken的默认超时时间(如果clientDetails的为null就取默认的,如果clientDetails的不为null取clientDetails中的) tokenServices.setAccessTokenValiditySeconds((int) TimeUnit.HOURS.toSeconds(2)); tokenServices.setRefreshTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(30)); endpoints.tokenServices(tokenServices); }