Class OAuthClientUtils

java.lang.Object
org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils

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

    • 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 jakarta.ws.rs.core.UriBuilder getAuthorizationURIBuilder(String authorizationServiceURI, String clientId, String redirectUri, String state, String scope)
    • getAuthorizationURIBuilder

      public static jakarta.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) 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
      Returns:
      ClientAccessToken access token
      Throws:
      OAuthServiceException
    • getAccessToken

      public static ClientAccessToken getAccessToken(String accessTokenServiceUri, Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader) throws OAuthServiceException
      Obtains the access token from OAuth AccessToken Service
      Parameters:
      accessTokenServiceUri - the AccessToken endpoint address
      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, 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, AccessTokenGrant grant) throws OAuthServiceException
      Obtains the access token from OAuth AccessToken Service using the initialized web client
      Parameters:
      accessTokenService - the AccessToken client
      grant - AccessTokenGrant grant
      Returns:
      ClientAccessToken access token
      Throws:
      OAuthServiceException
    • getAccessToken

      public static ClientAccessToken getAccessToken(org.apache.cxf.jaxrs.client.WebClient accessTokenService, AccessTokenGrant grant, Map<String,String> extraParams) throws OAuthServiceException
      Obtains the access token from OAuth AccessToken Service using the initialized web client
      Parameters:
      accessTokenService - the AccessToken client
      grant - AccessTokenGrant grant
      extraParams - extra parameters
      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
    • refreshAccessToken

      public static ClientAccessToken refreshAccessToken(org.apache.cxf.jaxrs.client.WebClient accessTokenService, ClientAccessToken at)
    • refreshAccessToken

      public static ClientAccessToken refreshAccessToken(org.apache.cxf.jaxrs.client.WebClient accessTokenService, Consumer consumer, ClientAccessToken at)
    • refreshAccessToken

      public static ClientAccessToken refreshAccessToken(org.apache.cxf.jaxrs.client.WebClient accessTokenService, Consumer consumer, ClientAccessToken at, String scope, boolean setAuthorizationHeader) throws OAuthServiceException
      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
    • fromMapToClientToken

      public static ClientAccessToken fromMapToClientToken(Map<String,String> map)
    • fromMapToClientToken

      public static ClientAccessToken fromMapToClientToken(Map<String,String> map, String defaultTokenType)
    • createAuthorizationHeader

      public static String createAuthorizationHeader(ClientAccessToken accessToken) throws OAuthServiceException
      Creates OAuth Authorization header with Bearer scheme
      Parameters:
      accessToken - the access token
      Returns:
      the header value
      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)
    • getAuthorizationMetadata

      public static AuthorizationMetadata getAuthorizationMetadata(String issuerURL)