Package com.guinetik.rr.auth
Class OAuth2PasswordStrategy
- java.lang.Object
-
- com.guinetik.rr.auth.AbstractOAuth2Strategy
-
- com.guinetik.rr.auth.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.guinetik.rr.auth.AuthStrategy
AuthStrategy.AuthType
-
-
Field Summary
-
Fields inherited from class com.guinetik.rr.auth.AbstractOAuth2Strategy
accessToken, additionalParams, httpClient, isRefreshing, logger, oauthTokenUrl, tokenExpiryTime
-
-
Constructor Summary
Constructors Constructor Description OAuth2PasswordStrategy(String username, String password, String clientId, String clientSecret, String tokenUrl)Creates a new OAuth 2.0 password strategy.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetRefreshToken()Gets the current refresh token.AuthStrategy.AuthTypegetType()Returns the auth type of this strategy.protected Map<String,String>prepareTokenRequestParams()Prepares the parameters for the token request.protected booleanprocessTokenResponse(Map<String,Object> tokenResponse)Processes the token response and extracts relevant information.protected voidvalidateCredentials()Validates that all required credentials are present.-
Methods inherited from class com.guinetik.rr.auth.AbstractOAuth2Strategy
applyAuthHeaders, configureSsl, getAccessToken, getTokenExpiryTime, needsTokenRefresh, post, refreshCredentials
-
-
-
-
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 usernamepassword- the user's passwordclientId- 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 usernamepassword- the user's passwordclientId- 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 URLadditionalParams- additional parameters to include in the token request
-
-
Method Detail
-
getType
public AuthStrategy.AuthType getType()
Description copied from interface:AuthStrategyReturns the auth type of this strategy.- Returns:
- the authentication type
-
validateCredentials
protected void validateCredentials()
Validates that all required credentials are present.- Specified by:
validateCredentialsin classAbstractOAuth2Strategy- Throws:
TokenRefreshException- if the username or password is not provided.
-
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:
prepareTokenRequestParamsin classAbstractOAuth2Strategy- 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:
processTokenResponsein classAbstractOAuth2Strategy- 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
-
-