App Authentication with an API Key

Configuration.Default.BasePath = "<Endpoint URL>";
string decodedAPIKey = Encoding.ASCII.GetString(Convert.FromBase64String(<API Key>));
string[] decodeApiTokens = decodedAPIKey.Split(':');
Configuration.Default.Username = decodeApiTokens[0];
Configuration.Default.Password = decodeApiTokens[1];

AuthenticationApi authenticationApi = new AuthenticationApi();
AuthResponse response = authenticationApi.Authorize();
Configuration.Default.AddApiKey("Authorization", response.AccessToken);
Configuration.Default.AddApiKeyPrefix("Authorization", "Bearer");

Go

client := sdkms.Client{
      Endpoint: "<Endpoint URL>",
      HTTPClient: http.DefaultClient,
}
ctx := context.Background()
_, err := client. AuthenticateWithAPIKey(ctx, <API Key>)

Java

ApiClient apiClient = new ApiClient();
apiClient.setBasePath(<Endpoint URL>);
apiClient.setBasicAuthString(<API Key>);
AuthenticationApi authenticationApi = new AuthenticationApi(apiClient);
AuthResponse authResponse = authenticationApi.authorize();
ApiKeyAuth bearerTokenAuth = (ApiKeyAuth) apiClient.getAuthentication("bearerToken");
bearerTokenAuth.setApiKey(authResponse.getAccessToken());
bearerTokenAuth.setApiKeyPrefix("Bearer");

Python

config = sdkms.v1.Configuration()
config.host = "<Endpoint URL>"
config.app_api_key = <API Key>
client = sdkms.v1.ApiClient(configuration=config)
auth_instance = sdkms.v1.AuthenticationApi(api_client=client)
auth = auth_instance.authorize()
config.api_key['Authorization'] = auth.access_token
config.api_key_prefix['Authorization'] = 'Bearer'

PHP

$configuration = new SdkmsClient\Configuration();
$decodedApiKey = base64_decode('<API Key>')
$decodedApiTokens = explode(":",$decodedApiKey);
$configuration->setUsername($decodedApiTokens[0]);
$configuration->setPassword($decodedApiTokens[1]);
$configuration->setHost('<Endpoint URL>');
$client = new SdkmsClient\ApiClient($configuration);
      
$api_instance = new SdkmsClient\Api\AuthenticationApi($client);
$auth_response = api_instance.authorize();
$configuration->setApiKey('Authorization', $auth_response->getAccessToken());
$configuration->setApiKeyPrefix('Authorization', 'Bearer');
$auth_response = api_instance.authorize();

Javascript

var FortanixSdkmsRestApi = require('fortanix_sdkms_rest_api');
var client = FortanixSdkmsRestApi.ApiClient.instance;
client.basePath = '<Endpoint URL>';
let buff = new Buffer('<API Key>;', 'base64');
let decodedApiKey = buff.toString('ascii');
let decodedApiTokens = decodedApiKeytr.split(":");
client.authentications.basicAuth.username = decodedApiTokens[0];
client.authentications.basicAuth.password = decodedApiTokens[1];

var authCallback = function(error, data, response) {
    if (error) {
        console.error("Error: " + JSON.stringify(response));
    } else {
        client.authentications.bearerToken.apiKey = data.accessToken;
        client.authentications.bearerToken.apiKeyPrefix = "Bearer";
        // continue with other API calls.
    }
};
var authApi = new FortanixSdkmsRestApi.AuthenticationApi()
authApi.authorize(authCallback);

REST API using curl

$ curl <Endpoint URL>/sys/v1/session/auth -X POST -H 'Authorization: Basic <API Key>'
> {"token_type":"Bearer","expires_in":600,"access_token":"YhXwwa- 6C...L9kRxswmPZkEFQ2ig5g","entity_id":"7916b324-33a1-4a06-8778-59ec0492bb10"}

#use the "access_token" as Bearer Auth in other API requests. E.g: 
$ curl <Endpoint URL>/other_apis -H 'Authorization: Bearer YhXwwa- 6C...L9kRxswmPZkEFQ2ig5g ' ...