validateToken method

Future<bool> validateToken(
  1. String bearerToken,
  2. CyberSiaraModel cieraModel
)

Validates the provided bearer token by making an API request.

This function sends a GET request to the validateToken endpoint to verify whether the provided bearer token is valid. If the API response message is "Verified", it returns true; otherwise, it returns false.

Parameters:

  • bearerToken: The authentication token to be validated.
  • cieraModel: An instance of CyberCieraModel containing API credentials.

Function Workflow:

  1. Initializes isSuccess to false.
  2. Calls ApiManager.get() with the validateToken endpoint, passing the privateKey and bearerToken as parameters.
  3. Parses the API response:
    • If "Message" is "Verified", sets isSuccess to true.
  4. Catches and logs any errors encountered.
  5. Returns isSuccess indicating whether validation was successful.

Returns:

  • true if the token is verified.
  • false if verification fails or an error occurs.

Implementation

Future<bool> validateToken(String bearerToken, CyberSiaraModel cieraModel) async {
  bool isSuccess = false;
  try {
    ResponseAPI responseAPI =
        await ApiManager.get(methodName: ApiConstant.validateToken, privateKey: cieraModel.privateKey, bearerToken: bearerToken);
    Map<String, dynamic> valueMap = responseAPI.response;
    if (valueMap["Message"] == "Verified") {
      isSuccess = true;
    }
  } catch (err) {
    error(err.toString());
  }
  return isSuccess;
}