Navigation

API Key Authentication

Overview

The API Key authentication provider allows users to log in using generated keys. There are two types of API keys in MongoDB Realm: server keys and user keys.

Server API Keys

Server API keys are generated in the Realm UI. Creating a server API key associates that API key with an automatically created Realm server user. Provide a server key to external applications and services to allow them to authenticate directly with Realm.

User API Keys

User API keys are generated for specific application users by the client SDKs. You can allow devices or services to communicate with Realm on behalf of a user by associating a unique user API key with each device.

User keys are always associated with a user object created by another authentication provider. Each user can associate up to 20 user keys with their account.

Configuration

You can enable and configure the API Key authentication provider from the Realm UI by selecting API Keys from the Users > Providers page.

You can enable and configure the API Key authentication provider with realm-cli by importing an application directory that contains a configuration file for the provider.

The configuration file must be named api-key.json and stored in the /auth_providers directory. Configuration files for the API Key authentication provider have the following form:

/auth_providers/api-key.json
{
  "name": "api-key",
  "type": "api-key",
  "disabled": false
}

Note

The API Key authentication provider does not have any provider-specific configuration options.

Create a Server API Key

To create a new server API key, navigate to the API Key authentication configuration page in the Realm UI and click Create API Key. Enter a unique name for the key and click Save.

Important

Remember to copy the server key’s value as soon as you create it. Once you leave the provider configuration page or disable the key you cannot retrieve the value from the Realm UI.

Summary

  • The Realm API Key authentication provider allows users and services to connect to a Realm app using API keys that look like a string of characters.
  • User API Keys allow a user to interact with services via the Realm SDK. They are automatically generated in the client SDK.
  • Server API Keys allow external services to interact with your Realm app. These keys can only be generated via the Realm UI.