Area: API
Sub-Area: Authentication
Applies to: OSS + Cloud
Issue
API requests fail with authentication errors, an access token has expired, or you can't generate a token.
Messages you may see:
- HTTP 401
Unauthorized to perform this action.(the request had no valid authentication) -
Failed to validate DataHub token. Token has expired.(server-side token validation) -
Failed to validate DataHub token: Token has been revoked(server-side token validation) -
Unauthorized to perform this action. Please contact your DataHub administrator.(you lack the privilege to create the token) -
Token based authentication is currently disabled. Contact your DataHub administrator to enable this feature.(shown on the Access Tokens page) -
Never-expiring access tokens (NO_EXPIRY) cannot be created because ACCESS_TOKEN_ALLOW_NO_EXPIRY is false. ...(you asked for a token that never expires)
You Might Be Asking
- How do I create an API access token?
- Why is my token not working?
- How do I refresh an expired token?
- Why is the "Generate new token" button disabled?
Cause
- Expired or revoked token. Validation fails with the expiry or revoked messages above. A token can't be extended. You create a new one.
- Missing privilege. In the UI, the generate button is disabled unless token authentication is enabled and you have the Generate Personal Access Tokens platform privilege. The Manage All Access Tokens privilege does not enable the button. By default, the built-in policy "All Users - Base Platform Privileges" grants Generate Personal Access Tokens to all users. If that policy was edited or deactivated, users lose the privilege.
- Token authentication disabled. The Access Tokens page shows the "Token based authentication is currently disabled" alert when token authentication is off.
- Invalid GraphQL input. Duration values, required fields and selected fields must match the schema (see Solution).
- Never-expiring tokens are off by default. DataHub Cloud v2.2.0 disabled them by default. Existing never-expiring tokens keep working.
-
Token in a URL query parameter for MCP. MCP endpoints accept the token only in the
Authorization: Bearer <token>header. Atokenquery parameter returns 400 Bad Request. The DataHub Cloud v2.1.2 release notes list this change.
Solution
1. Create a personal access token in the UI
- Go to Settings > Access Tokens.
- Select "Generate new token".
- Enter a name and choose an expiration from the "Expires in" list. The list shows the durations the server allows. "Never" appears only if the server allows never-expiring tokens.
- Copy the token from the "New Access Token" dialog before you close it. The dialog warns that you won't be able to see it again.
If the button is disabled, ask an admin to grant you Generate Personal Access Tokens. Policies are on the Policies tab of Settings > Permissions. See Policies.
See Creating personal access tokens.
2. Create a token with GraphQL
mutation createAccessToken {
createAccessToken(
input: {
type: PERSONAL
actorUrn: "urn:li:corpuser:<your-username>"
duration: ONE_MONTH
name: "API Integration Token"
description: "Token for automated ingestion"
}
) {
accessToken
metadata {
urn
}
}
}
Rules for the input:
-
type,actorUrnandnameare required.typeisPERSONALorSERVICE_ACCOUNT. - Give exactly one of
durationordurationIso. If you give both or neither, you getExactly one of duration or durationIso must be provided when creating an access token. - Valid
durationvalues areONE_HOUR,ONE_DAY,ONE_WEEK,ONE_MONTH,THREE_MONTHS,SIX_MONTHS,ONE_YEARandNO_EXPIRY. Other values, such asTWO_MONTHS, fail GraphQL validation. -
durationIsotakes an ISO-8601 duration such asP30D. The default allowed list isPT1H,P1D,P7D,P30D,P90D,P180DandP365D. Anything else fails withAccess token duration '<iso>' is not allowed. .... -
accessTokenis the token string.expiresAtis not a field of the returnedAccessToken. On create,metadatahas onlyurnandtypefilled in, so selectmetadata { urn }. - There is no scope or permission-level field on the input.
Who may create which token:
- For yourself (
actorUrnis your own URN), you need Generate Personal Access Tokens. - For another user, you need Manage All Access Tokens. This is done through the API, not the UI.
- For a
SERVICE_ACCOUNTtoken, you need Manage Service Accounts, andactorUrnmust be a service account. Otherwise you getThe specified URN is not a service account: <urn>.
Without the right privilege you get Unauthorized to perform this action. Please contact your DataHub administrator.
See Token management.
3. Use the token
Send it as a Bearer header to the GraphQL endpoint with POST. The call runs with the privileges of the token's actor. Use the same host you browse DataHub on.
curl -X POST https://<your-datahub-url>/api/graphql \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query": "{ me { corpUser { urn } platformPrivileges { generatePersonalAccessTokens manageTokens } } }"}'
me returns corpUser and platformPrivileges only. Fields such as me { username } and me { privileges { ... } } do not exist.
See Set up GraphQL.
For the Python REST emitter, pass the token. On DataHub Cloud, the server URL is https://<name>.acryl.io/gms.
from datahub.emitter.rest_emitter import DatahubRestEmitter
emitter = DatahubRestEmitter(
gms_server="https://<name>.acryl.io/gms",
token="YOUR_ACCESS_TOKEN",
)
emitter.test_connection()
test_connection() raises on failure. A 401 gives Unable to connect to <gms>/config - got an authentication error: <body>. If you point at the frontend instead of GMS, the message says you connected to the frontend service.
See REST emitter.
4. Replace an expired token
There is no refresh call. A token can't be extended. Before it expires, generate a new token in Settings > Access Tokens (or create one with the GraphQL mutation above), update your clients, then revoke the old one with revokeAccessToken(tokenId: String!). listAccessTokens lists existing tokens and getAccessTokenMetadata(token: String!) finds the actor of a raw token.
Don't send a username and password as Basic auth to GMS. GMS's system authenticator accepts a Basic header only when the credentials match the configured system client id and secret, and rejects anything else.
For automation, use a service account instead of a personal token. Go to Users & Groups > Service Accounts. The tab shows only for users with Manage Service Accounts. See Service accounts.
5. Never-expiring tokens and allowed durations
- Cloud: you can't change these settings. Contact DataHub Support.
-
Self-hosted: set
ACCESS_TOKEN_ALLOW_NO_EXPIRY=trueon GMS to allowNO_EXPIRY.ACCESS_TOKEN_ALLOWED_DURATIONSsets the allowed list. Both are in the "Authentication Configuration" section of the environment variables page.
6. Changing a user's role
To set a role, use batchAssignRole(input: { roleUrn, actors: [...] }). It replaces the actor's existing role, and an undefined roleUrn removes the role. Don't run it on an admin user unless you mean to change that user's role.
7. MCP clients
Put the token in the Authorization: Bearer <token> header. If your client can't set headers, use mcp-remote with --header "Authorization: Bearer <token>". See MCP.
Never commit tokens to version control. Keep them in environment variables or a secret manager.
Related Documentation
- Personal access tokens
- Token management (GraphQL)
- Set up GraphQL
- Policies
- Service accounts
- MCP authentication
- REST emitter
- Environment variables
Tags: access-tokens, authentication, api, authorization, jwt, bearer-token, credentials, security