org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken Java Examples
The following examples show how to use
org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken.
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: OsiamTokenEnhancer.java From osiam with MIT License | 6 votes |
@Override public OAuth2AccessToken enhance(final OAuth2AccessToken accessToken, final OAuth2Authentication authentication) { DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken; Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put("expires_at", token.getExpiration()); if (token.getRefreshToken() != null) { DefaultExpiringOAuth2RefreshToken refreshToken = (DefaultExpiringOAuth2RefreshToken) token.getRefreshToken(); additionalInformation.put("refresh_token_expires_at", refreshToken.getExpiration()); } additionalInformation.put("client_id", authentication.getOAuth2Request().getClientId()); if (authentication.getUserAuthentication() != null && authentication.getPrincipal() instanceof User) { User user = (User) authentication.getPrincipal(); additionalInformation.put("user_name", user.getUserName()); additionalInformation.put("user_id", user.getId()); } token.setAdditionalInformation(additionalInformation); return accessToken; }
Example #2
Source File: YamiTokenServices.java From mall4j with GNU Affero General Public License v3.0 | 5 votes |
private OAuth2RefreshToken createRefreshToken(OAuth2Authentication authentication) { if (!isSupportRefreshToken(authentication.getOAuth2Request())) { return null; } int validitySeconds = getRefreshTokenValiditySeconds(authentication.getOAuth2Request()); String value = UUID.randomUUID().toString(); if (validitySeconds > 0) { return new DefaultExpiringOAuth2RefreshToken(value, new Date(System.currentTimeMillis() + (validitySeconds * 1000L))); } return new DefaultOAuth2RefreshToken(value); }
Example #3
Source File: UserInfoTokenServicesRefreshTokenTests.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Test public void withRestTemplate() { OAuth2ProtectedResourceDetails resource = new AuthorizationCodeResourceDetails(); OAuth2ClientContext context = new DefaultOAuth2ClientContext(); DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO"); token.setRefreshToken(new DefaultExpiringOAuth2RefreshToken("BAR", new Date(0L))); context.setAccessToken(token); this.services.setRestTemplate(new OAuth2RestTemplate(resource, context)); assertThat(this.services.loadAuthentication("FOO").getName()).isEqualTo("me"); assertThat(context.getAccessToken().getValue()).isEqualTo("FOO"); // The refresh token is still intact assertThat(context.getAccessToken().getRefreshToken()).isEqualTo(token.getRefreshToken()); }
Example #4
Source File: SmartlingAuthorizationCodeAccessTokenProvider.java From mojito with Apache License 2.0 | 5 votes |
DefaultOAuth2AccessToken getDefaultOAuth2AccessToken(DateTime now, AuthenticationResponse authenticationResponse) { AuthenticationData data = authenticationResponse.getData(); DefaultOAuth2AccessToken defaultOAuth2AccessToken = new DefaultOAuth2AccessToken(data.getAccessToken()); defaultOAuth2AccessToken.setExpiration(now.plusSeconds(data.getExpiresIn()).toDate()); defaultOAuth2AccessToken.setRefreshToken(new DefaultExpiringOAuth2RefreshToken( data.getRefreshToken(), now.plusSeconds(data.getRefreshExpiresIn()).toDate())); return defaultOAuth2AccessToken; }