Create & Manage API Keys¶
Create a User API Key¶
Important
Store the API Key Value
The SDK only returns the value of the user API key when you create it. Make
sure to store the key
value securely so that you can use it to log in.
If you lose or do not store the key
value there is no way to recover it.
You will need to create a new user API key.
var newKey = await user.ApiKeys.CreateAsync("someKeyName"); Console.WriteLine($"I created a key named {newKey.Name}. " + $"Is it enabled? {newKey.IsEnabled}");
Look up a User API Key¶
To get a single key:
var key = await user.ApiKeys.FetchAsync(ObjectId.Parse("00112233445566778899aabb")); Console.WriteLine($"I fetched the key named {key.Name}. " + $"Is it enabled? {key.IsEnabled}");
To get all keys:
var allKeys = await user.ApiKeys.FetchAllAsync(); foreach (var key in allKeys) { Console.WriteLine($"I fetched the key named {key.Name}. " + $"Is it enabled? {key.IsEnabled}"); }
Enable or Disable an API Key¶
var key = await user.ApiKeys.FetchAsync(ObjectId.Parse("00112233445566778899aabb")); if (!key.IsEnabled) { // enable the key await user.ApiKeys.EnableAsync(key.Id); } else { // disable the key await user.ApiKeys.DisableAsync(key.Id); }
Delete an API Key¶
await user.ApiKeys.DeleteAsync(ObjectId.Parse("00112233445566778899aabb"));
Give Feedback