All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.connector.automationanywhere.auth.ApiKeyAuthProvider Maven / Gradle / Ivy

There is a newer version: 8.6.0-alpha5
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. Licensed under a proprietary license.
 * See the License.txt file for more information. You may not use this file
 * except in compliance with the proprietary license.
 */
package io.camunda.connector.automationanywhere.auth;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.connector.automationanywhere.model.AutomationAnywhereHttpRequestBuilder;
import io.camunda.connector.http.base.model.HttpMethod;
import io.camunda.connector.http.base.services.HttpService;
import java.util.Map;

public record ApiKeyAuthProvider(
    String username, String apiKey, String controlRoomUrl, Integer connectionTimeoutInSeconds)
    implements AuthenticationProvider {

  private static final String USERNAME_KEY = "username";
  private static final String API_KEY = "apiKey";

  @Override
  public String obtainToken(final HttpService httpService, final ObjectMapper objectMapper)
      throws Exception {

    final var request =
        new AutomationAnywhereHttpRequestBuilder()
            .withUrl(getAuthenticationRequestUrl(controlRoomUrl))
            .withBody(createRequestBody())
            .withMethod(HttpMethod.POST)
            .withTimeoutInSeconds(connectionTimeoutInSeconds)
            .build();

    final var result = httpService.executeConnectorRequest(request);
    return fetchToken(result, objectMapper);
  }

  private Map createRequestBody() {
    return Map.of(USERNAME_KEY, username, API_KEY, apiKey);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy