protected OAuth2AccessToken acquireAccessToken ( ) throws UserRedirectRequiredException { AccessTokenRequest tokenRequest = oAuth2ClientContext . getAccessTokenRequest ( ) ; if ( tokenRequest == null ) { throw new AccessTokenRequiredException ( "Cannot find valid context on request for resource '" + resource . getId ( ) + "'." , resource ) ; } String stateKey = tokenRequest . getStateKey ( ) ; if ( stateKey != null ) { tokenRequest . setPreservedState ( oAuth2ClientContext . removePreservedState ( stateKey ) ) ; } OAuth2AccessToken existingToken = oAuth2ClientContext . getAccessToken ( ) ; if ( existingToken != null ) { oAuth2ClientContext . setAccessToken ( existingToken ) ; } OAuth2AccessToken obtainableAccessToken ; obtainableAccessToken = accessTokenProvider . obtainAccessToken ( resource , tokenRequest ) ; if ( obtainableAccessToken == null || obtainableAccessToken . getValue ( ) == null ) { throw new IllegalStateException ( " Access token provider returned a null token, which is illegal according to the contract." ) ; } oAuth2ClientContext . setAccessToken ( obtainableAccessToken ) ; return obtainableAccessToken ; }
Try to acquire the token using a access token provider .