public static OAuthAccessToken getOAuthAccessToken ( RequestContext requestContext , String provider , String ... scopes ) { HttpSession session = requestContext . getRequest ( ) . getSession ( ) ; OAuthAccessToken [ ] accessTokens = ( OAuthAccessToken [ ] ) session . getAttribute ( String . format ( PROVIDER_ACCESS_TOKENS , provider ) ) ; if ( accessTokens != null ) { for ( OAuthAccessToken accessToken : accessTokens ) { List < String > accessTokenScopes = accessToken . getScopes ( ) != null ? Arrays . asList ( accessToken . getScopes ( ) ) : Collections . emptyList ( ) ; if ( scopes == null || accessTokenScopes . containsAll ( Arrays . asList ( scopes ) ) ) { if ( isOAuthTokenExpired ( accessToken ) ) { if ( "Keycloak" . equals ( provider ) ) { return getKeycloakStrategy ( ) . refreshToken ( requestContext , accessToken ) ; } } else { return accessToken ; } } } } return null ; }
Returns OAuth previously stored access token from HTTP session