Class OAuthClientUtils


  • public final class OAuthClientUtils
    extends Object
    The utility class for simplifying working with OAuth servers
    • Method Detail

      • getAuthorizationURI

        public static URI getAuthorizationURI​(String authorizationServiceURI,
                                              String clientId,
                                              String redirectUri,
                                              String state,
                                              String scope)
        Builds a complete URI for redirecting to OAuth Authorization Service
        Parameters:
        authorizationServiceURI - the service endpoint address
        clientId - client registration id
        redirectUri - the uri the authorization code will be posted to
        state - the client state, example the key or the encrypted token representing the info about the current end user's request
        Returns:
        authorization service URI
      • getAuthorizationURIBuilder

        public static javax.ws.rs.core.UriBuilder getAuthorizationURIBuilder​(String authorizationServiceURI,
                                                                             String clientId,
                                                                             String redirectUri,
                                                                             String state,
                                                                             String scope)
      • getAuthorizationURIBuilder

        public static javax.ws.rs.core.UriBuilder getAuthorizationURIBuilder​(String authorizationServiceURI,
                                                                             String clientId,
                                                                             String scope)
        Creates the builder for building OAuth AuthorizationService URIs
        Parameters:
        authorizationServiceURI - the service endpoint address
        clientId - client registration id
        scope - the optional scope; if not specified then the authorization service will allocate the default scope
        Returns:
        the builder
      • getAccessToken

        public static ClientAccessToken getAccessToken​(org.apache.cxf.jaxrs.client.WebClient accessTokenService,
                                                       Consumer consumer,
                                                       AccessTokenGrant grant,
                                                       boolean setAuthorizationHeader)
        Obtains the access token from OAuth AccessToken Service using the initialized web client
        Parameters:
        accessTokenService - the AccessToken client
        consumer - Consumer representing the registered client.
        grant - AccessTokenGrant grant
        setAuthorizationHeader - if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload
        Returns:
        ClientAccessToken access token
        Throws:
        OAuthServiceException
      • getAccessToken

        public static ClientAccessToken getAccessToken​(org.apache.cxf.jaxrs.client.WebClient accessTokenService,
                                                       Consumer consumer,
                                                       AccessTokenGrant grant,
                                                       Map<String,​String> extraParams,
                                                       boolean setAuthorizationHeader)
                                                throws OAuthServiceException
        Obtains the access token from OAuth AccessToken Service using the initialized web client
        Parameters:
        accessTokenService - the AccessToken client
        consumer - Consumer representing the registered client.
        grant - AccessTokenGrant grant
        extraParams - extra parameters
        setAuthorizationHeader - if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload
        Returns:
        ClientAccessToken access token
        Throws:
        OAuthServiceException
      • getAccessToken

        public static ClientAccessToken getAccessToken​(org.apache.cxf.jaxrs.client.WebClient accessTokenService,
                                                       Consumer consumer,
                                                       AccessTokenGrant grant,
                                                       Map<String,​String> extraParams,
                                                       String defaultTokenType,
                                                       boolean setAuthorizationHeader)
                                                throws OAuthServiceException
        Obtains the access token from OAuth AccessToken Service using the initialized web client
        Parameters:
        accessTokenService - the AccessToken client
        consumer - Consumer representing the registered client.
        grant - AccessTokenGrant grant
        extraParams - extra parameters
        defaultTokenType - default expected token type - some early well-known OAuth2 services do not return a required token_type parameter
        setAuthorizationHeader - if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload
        Returns:
        ClientAccessToken access token
        Throws:
        OAuthServiceException
      • createAuthorizationHeader

        public static String createAuthorizationHeader​(ClientAccessToken accessToken,
                                                       HttpRequestProperties httpProps)
                                                throws OAuthServiceException
        Creates OAuth Authorization header with the scheme that may require an access to the current HTTP request properties
        Parameters:
        accessToken - the access token
        httpProps - http request properties, can be null for Bearer tokens
        Returns:
        the header value
        Throws:
        OAuthServiceException
      • setAuthorizationHeader

        public static void setAuthorizationHeader​(org.apache.cxf.jaxrs.client.WebClient wc,
                                                  ClientAccessToken accessToken)
      • setAuthorizationHeader

        public static void setAuthorizationHeader​(org.apache.cxf.jaxrs.client.WebClient wc,
                                                  ClientAccessToken accessToken,
                                                  String httpVerb)