Class OAuth2PasswordStrategy

  • All Implemented Interfaces:
    AuthStrategy, RocketSSL.SSLAware

    public class OAuth2PasswordStrategy
    extends AbstractOAuth2Strategy
    Authentication strategy that implements OAuth 2.0 password flow. This strategy gets and refreshes OAuth 2.0 access tokens using username and password.
    • Constructor Detail

      • OAuth2PasswordStrategy

        public OAuth2PasswordStrategy​(String username,
                                      String password,
                                      String clientId,
                                      String clientSecret,
                                      String tokenUrl)
        Creates a new OAuth 2.0 password strategy.
        Parameters:
        username - the user's username
        password - the user's password
        clientId - the OAuth 2.0 client ID (optional, can be null)
        clientSecret - the OAuth 2.0 client secret (optional, can be null)
        tokenUrl - the OAuth 2.0 token endpoint URL
      • OAuth2PasswordStrategy

        public OAuth2PasswordStrategy​(String username,
                                      String password,
                                      String clientId,
                                      String clientSecret,
                                      String tokenUrl,
                                      Map<String,​String> additionalParams)
        Creates a new OAuth 2.0 password strategy with additional parameters.
        Parameters:
        username - the user's username
        password - the user's password
        clientId - the OAuth 2.0 client ID (optional, can be null)
        clientSecret - the OAuth 2.0 client secret (optional, can be null)
        tokenUrl - the OAuth 2.0 token endpoint URL
        additionalParams - additional parameters to include in the token request
    • Method Detail

      • getType

        public AuthStrategy.AuthType getType()
        Description copied from interface: AuthStrategy
        Returns the auth type of this strategy.
        Returns:
        the authentication type
      • prepareTokenRequestParams

        protected Map<String,​String> prepareTokenRequestParams()
        Prepares the parameters for the token request.

        Prepares parameters for the OAuth 2.0 password grant type or refresh token grant type. If a refresh token is available, it will be used. Otherwise, username and password will be used. Client ID and client secret are included if provided.

        Specified by:
        prepareTokenRequestParams in class AbstractOAuth2Strategy
        Returns:
        map of parameters to include in the token request
      • processTokenResponse

        protected boolean processTokenResponse​(Map<String,​Object> tokenResponse)
        Processes the token response and extracts relevant information.

        Processes the token response, extracting and storing the refresh_token if present, in addition to the access_token and expiry time handled by the superclass.

        Overrides:
        processTokenResponse in class AbstractOAuth2Strategy
        Parameters:
        tokenResponse - the parsed token response
        Returns:
        true if the token was successfully refreshed, false otherwise
      • getRefreshToken

        public String getRefreshToken()
        Gets the current refresh token.
        Returns:
        the current refresh token, or null if not yet obtained