Api Keys

Managing Authentication and Access Control

The API keys endpoint in the Babel Licensing Service API is a crucial component designed for the management and handling of API keys, which are essential for authenticating and gaining access to the service. This endpoint supports multiple HTTP methods, each serving a specific purpose in the lifecycle of API keys.

Get

This method is utilized to fetch information about existing API keys. It allows users to access details such as key identifiers, associated permissions, and the user to which each key is assigned. This function is essential for monitoring and managing API key distribution, ensuring each key is used in accordance with its intended purpose and security protocols.

Examples

using System.Net.Http;
using Babel.Licensing.Service.Management;

// See WebApiClient in Code Examples paragraph
using var httpClient = CreateHttpClient();

var request = new GetApiKeysRequest();
var httpMessage = MakeApiRequest(request, HttpMethod.Get, "/v1/api-keys");

var result = await httpClient.SendAsync(httpMessage);
var response = await ParseResponseAsync<GetApiKeysResponse>(result);

Post

The POST method facilitates the generation of new API keys. It is used for creating keys that grant access to the API, specifying the scope and level of access each key provides. This method is crucial for expanding access to new users or services, enabling controlled and tracked interactions with the API.

Examples

using System.Net.Http;
using Babel.Licensing.Service.Management;

using var httpClient = CreateHttpClient();

var create = new InsertApiKeyRequest();
create.ApiKey = new ApiKey();
// Assign a name to the API key
create.ApiKey.Name = "Administrator API Key";
// Set the Administrator User ID
create.ApiKey.OwnerId = "725dc5f3-a4d2-4566-be63-356daa8a7367";
// Set permissions (Read = 1, Write = 2, Delete = 4)
create.ApiKey.Permissions = 7;

var httpMessage = MakeApiRequest(create, HttpMethod.Post, "/v1/api-keys");
var result = await httpClient.SendAsync(httpMessage);
var createResponse = await ParseResponseAsync<InsertApiKeyResponse>(result);

Put

Employing the PUT method allows for updates to the attributes of existing API keys. This might include changing the scope of access, modifying associated permissions, or updating the key’s expiration date. This method is vital for maintaining the relevance and security of API keys, adapting them to changing requirements or security policies.

Examples

using System.Net.Http;
using Babel.Licensing.Service.Management;

using var httpClient = CreateHttpClient();

var update = new UpdateApiKeyRequest();
update.ApiKey = new ApiKey();
// Set the ID of the API key to update
update.ApiKey.Id = 3;
// Set permissions (Read = 1, Write = 2, Delete = 4)
update.ApiKey.Permissions = 7;
// Change description
update.ApiKey.Description = "Assign read write permissions to sales.";

var httpMessage = MakeApiRequest(update, HttpMethod.Put, "/v1/api-keys");

var result = await httpClient.SendAsync(httpMessage);
var updateResponse = await ParseResponseAsync<UpdateApiKeyResponse>(result);

Delete

The DELETE method is used for invalidating and removing API keys from the system. This action is typically taken when a key is no longer needed, has been compromised, or when its associated user or service no longer requires access to the API. This is a critical step in API key lifecycle management, ensuring that only active and secure keys are in circulation.

Examples

using System.Net.Http;
using Babel.Licensing.Service.Management;

using var httpClient = CreateHttpClient();

var delete = new DeleteApiKeyRequest();
// Set the ID of the API key to delete
delete.ApiKeyId = 27;

var httpMessage = MakeApiRequest(delete, HttpMethod.Delete, $"/v1/api-keys/{delete.ApiKeyId}");
var result = await httpClient.SendAsync(httpMessage);

var deleteResponse = await ParseResponseAsync<DeleteApiKeyResponse>(result);

Each interaction with this endpoint ensures secure and controlled access to the Babel Licensing Service, making it a fundamental aspect of the API's security and access management features. The endpoint's responses are well-defined, indicating successful operations or errors, thereby facilitating efficient error handling and debugging.

Last updated