Class AuthClient
java.lang.Object
com.developer.nefarious.zjoule.plugin.auth.AuthClient
- All Implemented Interfaces:
IAuthClient
The
AuthClient
class provides functionality to authenticate with a service
and retrieve access tokens. It interacts with memory storage for access tokens
and service keys and uses an HTTP client to make requests to the authentication server.-
Constructor Summary
ConstructorDescriptionAuthClient
(IMemoryObject<AccessToken> memoryAccessToken, IMemoryObject<ServiceKey> memoryServiceKey, IAuthClientHelper authClientHelper) Constructs anAuthClient
instance with the given dependencies. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the current access token.Retrieves a new access token using the stored service key.getNewAccessToken
(ServiceKey serviceKey) Retrieves a new access token using the provided service key.Retrieves the service URL from the stored service key.
-
Constructor Details
-
AuthClient
public AuthClient(IMemoryObject<AccessToken> memoryAccessToken, IMemoryObject<ServiceKey> memoryServiceKey, IAuthClientHelper authClientHelper) Constructs anAuthClient
instance with the given dependencies.- Parameters:
memoryAccessToken
- the memory storage for access tokensmemoryServiceKey
- the memory storage for service keysauthClientHelper
- the helper for constructing and handling authentication requests
-
-
Method Details
-
getAccessToken
Retrieves the current access token. If the token is valid, it returns the cached token; otherwise, it fetches a new token.- Specified by:
getAccessToken
in interfaceIAuthClient
- Returns:
- the access token as a
String
- Throws:
IOException
- if an I/O error occursInterruptedException
- if the operation is interrupted
-
getNewAccessToken
Retrieves a new access token using the stored service key.- Specified by:
getNewAccessToken
in interfaceIAuthClient
- Returns:
- the new access token as a
String
- Throws:
IOException
- if an I/O error occursInterruptedException
- if the operation is interrupted
-
getNewAccessToken
Retrieves a new access token using the provided service key.- Specified by:
getNewAccessToken
in interfaceIAuthClient
- Parameters:
serviceKey
- theServiceKey
used for authentication- Returns:
- the new access token as a
String
- Throws:
IOException
- if an I/O error occursInterruptedException
- if the operation is interrupted
-
getServiceUrl
Retrieves the service URL from the stored service key.- Specified by:
getServiceUrl
in interfaceIAuthClient
- Returns:
- the service URL as a
String
-