public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource, OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException, OAuth2AccessDeniedException { MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.add("grant_type", "refresh_token"); form.add("refresh_token", refreshToken.getValue()); return retrieveToken(request, resource, form, new HttpHeaders()); }
@Override public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { return readAuthentication(token.getValue()); }
@Override public void removeRefreshToken(OAuth2RefreshToken refreshToken) { removeRefreshToken(refreshToken.getValue()); }
@Override public void removeRefreshToken(OAuth2RefreshToken token) { remove(token.getValue()); }
@Override public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) { removeAccessTokenUsingRefreshToken(refreshToken.getValue()); }
@Override public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { return readAuthenticationForRefreshToken(token.getValue()); }
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) { removeAccessTokenUsingRefreshToken(refreshToken.getValue()); }
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { return readAuthenticationForRefreshToken(token.getValue()); }
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) { removeAccessTokenUsingRefreshToken(refreshToken.getValue()); }
public void removeRefreshToken(OAuth2RefreshToken refreshToken) { removeRefreshToken(refreshToken.getValue()); }
public void removeRefreshToken(OAuth2RefreshToken token) { removeRefreshToken(token.getValue()); }
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { return readAuthenticationForRefreshToken(token.getValue()); }
public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource, OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException, OAuth2AccessDeniedException { MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.add("grant_type", "refresh_token"); form.add("refresh_token", refreshToken.getValue()); try { return retrieveToken(request, resource, form, getHeadersForTokenRequest(request)); } catch (OAuth2AccessDeniedException e) { throw getRedirectForAuthorization((AuthorizationCodeResourceDetails) resource, request); } }
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) { jdbcTemplate.update(insertRefreshTokenSql, new Object[] { extractTokenKey(refreshToken.getValue()), new SqlLobValue(serializeRefreshToken(refreshToken)), new SqlLobValue(serializeAuthentication(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB, Types.BLOB }); }
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { if (this.flushCounter.incrementAndGet() >= this.flushInterval) { flush(); this.flushCounter.set(0); } this.accessTokenStore.put(token.getValue(), token); this.authenticationStore.put(token.getValue(), authentication); this.authenticationToAccessTokenStore.put(authenticationKeyGenerator.extractKey(authentication), token); if (!authentication.isClientOnly()) { addToCollection(this.userNameToAccessTokenStore, getApprovalKey(authentication), token); } addToCollection(this.clientIdToAccessTokenStore, authentication.getOAuth2Request().getClientId(), token); if (token.getExpiration() != null) { TokenExpiry expiry = new TokenExpiry(token.getValue(), token.getExpiration()); // Remove existing expiry for this token if present expiryQueue.remove(expiryMap.put(token.getValue(), expiry)); this.expiryQueue.put(expiry); } if (token.getRefreshToken() != null && token.getRefreshToken().getValue() != null) { this.refreshTokenToAccessTokenStore.put(token.getRefreshToken().getValue(), token.getValue()); this.accessTokenToRefreshTokenStore.put(token.getValue(), token.getRefreshToken().getValue()); } }
String getJwtRefreshToken(String clientId, String clientSecret, String userName, String password, String host) throws Exception { CompositeToken result = getTokensWithPasswordGrant(clientId, clientSecret, userName, password, host, "jwt"); assertNotNull(result.getRefreshToken().getValue()); return result.getRefreshToken().getValue(); }
protected DefaultOAuth2AccessToken prepareForSerialization(DefaultOAuth2AccessToken token) { //get original ID String id = token.getValue(); //nullify the access_token value token.setValue(null); //ensure that the ID is that of the refresh token token.getAdditionalInformation().put(ClaimConstants.JTI, token.getRefreshToken().getValue()); //delete the access token from token store tokenStore.delete(id, 0, IdentityZoneHolder.get().getId()); return token; }
/** * tests a happy-day flow of the refresh token provider. */ @Test public void testHappyDay() throws Exception { OAuth2AccessToken accessToken = getAccessToken("read write", "my-trusted-client"); // now use the refresh token to get a new access token. assertNotNull(accessToken.getRefreshToken()); OAuth2AccessToken newAccessToken = refreshAccessToken(accessToken.getRefreshToken().getValue()); assertFalse(newAccessToken.getValue().equals(accessToken.getValue())); verifyAccessTokens(accessToken, newAccessToken); }
protected JaxbOAuth2AccessToken convertToInternal(OAuth2AccessToken accessToken) { JaxbOAuth2AccessToken jaxbAccessToken = new JaxbOAuth2AccessToken(); jaxbAccessToken.setAccessToken(accessToken.getValue()); jaxbAccessToken.setExpriation(accessToken.getExpiration()); OAuth2RefreshToken refreshToken = accessToken.getRefreshToken(); if(refreshToken != null) { jaxbAccessToken.setRefreshToken(refreshToken.getValue()); } return jaxbAccessToken; }