API authentication
The two credentials the API accepts — API keys for your servers, access tokens for a signed-in user.
The API accepts two kinds of credential. Both are sent as a bearer token, and they are not interchangeable.
| API key | Access token | |
|---|---|---|
| Acts as | Your application, or for an organization key the application it names | One user, for your application |
| Reaches | /api/v1/manage/… | /api/v1/userinfo/ |
| How you get it | Created in the developer portal | The OAuth sign-in flow |
| Looks like | eitozx_… | An opaque string |
API keys
An API key lets your servers call the management API as your application, with no user signed in. Create one on your application's API keys tab, or an organization key on your organization's.
curl https://onefold.eitozx.com/api/v1/manage/users/ \
-H "Authorization: Bearer eitozx_YOUR_KEY"- Shown once. The key is stored hashed and can never be displayed again. Copy it into your secret manager when you create it.
- Only your users. A key reaches only the people who currently hold a grant with your application. When someone revokes your application, they leave its reach immediately.
- Server-side only. Never ship a key in a browser or mobile application.
Scopes
A key can be limited to some of the management API:
| Scope | Allows |
|---|---|
users:read | Read the users who have authorized your application |
application:read | Read your application's registration |
entitlements:read | Read your application's plan limits |
metadata:read | Read your own metadata about users |
metadata:write | Write your own metadata about users |
profile_fields:read | Read your users' organization profiles, including their answers to your sign-up questions |
profile_fields:write | Change your users' organization profile fields |
profile_activity:read | Read what happened between each user and your application |
analytics:read | Read your application's usage and analytics |
activity:read | Read your application's activity log |
A key with no scopes can reach the whole management API, not nothing. A key's scopes can be
changed after it is created. Each endpoint's page in this reference shows the scope it needs. A call outside a key's scopes is refused with 403 and
code: "api_key_scope_missing"; add the scope to the key, or use one that carries it.
Rotating and revoking
- Rotate a key to replace it without an outage: the old key keeps working for a grace period (24 hours by default) while you deploy the new one.
- Revoke a key to end it immediately.
A key's expiry is optional, and your organization can cap it. See Credential lifetime.
Organization API keys
An organization API key reaches the management API of every application the organization owns, including applications created after the key, with the same endpoints and scopes as an application's key. Create one on the organization's API keys tab. You need the API key permissions at organization level.
Because one key reaches several applications, each call names the application it acts on, in
the Onefold-Application header:
curl https://onefold.eitozx.com/api/v1/manage/users/ -H "Authorization: Bearer eitozx_YOUR_ORGANIZATION_KEY" -H "Onefold-Application: APPLICATION_ID"- The header is required. An organization key without it is refused with
400. - It must name an application the key reaches: one the organization owns and that is
serving. Any other value, whether malformed, unknown, another organization's or a deleted
application, is the same
404, which says nothing about which. - An application's own key ignores the header. It always acts on its own application and cannot reach another by naming it.
Each call spends the request budget of the application it names. The key's history in the portal shows which application each call acted on. An organization key is one credential across every application of the organization, so a leaked one reaches all of them: give it the scopes its job needs, and revoke it if you think it has leaked.
The error codes for both refusals are listed in Errors, and every management endpoint's page in the reference shows the header.
Access tokens
An access token comes from the sign-in flow and acts for the user who signed in. On this API it reaches one endpoint:
curl https://onefold.eitozx.com/api/v1/userinfo/ \
-H "Authorization: Bearer ACCESS_TOKEN"It returns the claims the user's granted scopes allow. See Scopes and claims and Tokens and sessions.
Failed authentication
| Status | code | Meaning |
|---|---|---|
401 | not_authenticated | No credential was sent, or it could not be read |
401 | authentication_failed | The credential is expired, revoked, or was never valid. Get a new one |
403 | permission_denied | The credential is valid but does not reach this endpoint |
403 | api_key_scope_missing | The API key lacks the scope this endpoint needs |