Class AbstractOAuth2Strategy

    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
      • oauthTokenUrl

        protected final String oauthTokenUrl
        OAuth 2.0 token endpoint URL to be used when refreshing credentials.
      • accessToken

        protected String accessToken
      • tokenExpiryTime

        protected Date tokenExpiryTime
      • isRefreshing

        protected boolean isRefreshing
    • Constructor Detail

      • AbstractOAuth2Strategy

        protected AbstractOAuth2Strategy​(String tokenUrl,
                                         Map<String,​String> additionalParams)
        Creates a new OAuth 2.0 strategy with additional parameters.
        Parameters:
        tokenUrl - the OAuth 2.0 token endpoint URL
        additionalParams - additional parameters to include in the token request
    • Method Detail

      • applyAuthHeaders

        public RocketHeaders applyAuthHeaders​(RocketHeaders headers)
        Description copied from interface: AuthStrategy
        Applies authentication headers to an existing HttpHeader object.
        Specified by:
        applyAuthHeaders in interface AuthStrategy
        Parameters:
        headers - the current HttpHeader to update
        Returns:
        the updated HttpHeader
      • needsTokenRefresh

        public boolean needsTokenRefresh()
        Description copied from interface: AuthStrategy
        Indicates whether this strategy needs a token refresh.
        Specified by:
        needsTokenRefresh in interface AuthStrategy
        Returns:
        true if token refresh is required
      • post

        protected String post​(String url,
                              Map<String,​String> formParams)
                       throws IOException
        Helper method to perform POST requests.
        Parameters:
        url - the URL to send the request to
        formParams - the form parameters to include in the request
        Returns:
        the response body as a string
        Throws:
        IOException - if an I/O error occurs
      • refreshCredentials

        public boolean refreshCredentials()
        Description copied from interface: AuthStrategy
        Handles refreshing the authentication credentials for strategies that support it.
        Specified by:
        refreshCredentials in interface AuthStrategy
        Returns:
        true if the credentials were successfully refreshed
      • validateCredentials

        protected abstract void validateCredentials()
        Validates that all required credentials are present.
        Throws:
        TokenRefreshException - if any required credentials are missing
      • prepareTokenRequestParams

        protected abstract Map<String,​String> prepareTokenRequestParams()
        Prepares the parameters for the token request.
        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.
        Parameters:
        tokenResponse - the parsed token response
        Returns:
        true if the token was successfully refreshed, false otherwise
        Throws:
        TokenRefreshException - if there was an error processing the token response
      • getAccessToken

        public String getAccessToken()
        Gets the current access token.
        Returns:
        the current access token, or null if not yet obtained
      • getTokenExpiryTime

        public Date getTokenExpiryTime()
        Gets the token expiry time.
        Returns:
        the token expiry time, or null if not yet obtained
      • configureSsl

        public void configureSsl​(SSLContext sslContext)
        Sets the SSL context for secure token requests.
        Specified by:
        configureSsl in interface RocketSSL.SSLAware
        Parameters:
        sslContext - the SSL context to use