Class AuthClient

java.lang.Object
io.github.alejo2075.enzonasdk.client.AuthClient

public class AuthClient extends Object
This class provides functionality to authenticate with the Enzona API and retrieve an access token. It encapsulates all necessary details like preparing HTTP requests, handling responses and managing errors.

Usage of this class involves providing consumer key and secret issued by Enzona and then calling getAccessToken() method to perform the authentication and receive an access token that can be used for subsequent API requests.

This class employs an HttpClient to send HTTP requests. It is initialized at the creation of the instance and reused for all requests to improve performance and resource management.

  • Constructor Details

    • AuthClient

      public AuthClient(String consumerKey, String consumerSecret)
      Constructs an AuthClient instance with the specified consumer key and secret.
      Parameters:
      consumerKey - The consumer key issued by Enzona for API authentication. Must not be null.
      consumerSecret - The consumer secret issued by Enzona for API authentication. Must not be null.
      Throws:
      NullPointerException - if either consumerKey or consumerSecret is null.
  • Method Details

    • getAccessToken

      public String getAccessToken() throws EnzonaException
      Retrieves an access token from Enzona's authentication server by sending a HTTP POST request. This token is necessary for making authorized API calls to Enzona.
      Returns:
      A String representing the access token.
      Throws:
      EnzonaException - if there is a failure in retrieving the access token, which may include HTTP errors, network problems, or issues with JSON parsing.