Area: API
Sub-Area: Authentication
Applies to: OSS + Cloud
Issue
Personal Access Token (PAT) creation fails, a token is rejected with an authentication error, or you are not sure which privileges a token needs. This affects API authentication and programmatic access to DataHub.
You Might Be Asking
- Why can't I create a token, or why is "Generate new token" greyed out?
- Why does the Access Tokens page say token authentication is disabled?
- Why does my API call return 401 "Unauthorized to perform this action."?
- Which duration values can I use, and why is "Never" missing?
Cause
- Missing privilege. The "Generate new token" 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 an admin edited or deactivated that policy, you lose the privilege.
- Token authentication disabled. The Access Tokens page shows "Token based authentication is currently disabled. Contact your DataHub administrator to enable this feature." when the app config reports token authentication as off.
-
Invalid duration. The
createAccessTokenAPI accepts onlyONE_HOUR,ONE_DAY,ONE_WEEK,ONE_MONTH,THREE_MONTHS,SIX_MONTHS,ONE_YEARandNO_EXPIRY. Values such as1_MONTH,3_MONTHSorTWO_MONTHSdon't exist and fail GraphQL validation. -
Never-expiring tokens are off by default. DataHub Cloud v2.2.0 disabled never-expiring tokens by default. Existing never-expiring tokens keep working. The "Never" option appears in the "Expires in" list only when the server allows it. A
NO_EXPIRYrequest when it isn't allowed fails with "Never-expiring access tokens (NO_EXPIRY) cannot be created because ACCESS_TOKEN_ALLOW_NO_EXPIRY is false. ..." - Expired or revoked token. The server rejects an expired token ("Failed to validate DataHub token. Token has expired.") and a revoked token ("Failed to validate DataHub token: Token has been revoked"). An unauthenticated request to a protected path gets HTTP 401 "Unauthorized to perform this action."
Solution
Note: DataHub Cloud customers can't set server configuration. If a step below needs a server setting changed, contact DataHub Support.
-
Check your privileges. Run this query against
/api/graphqlwith a working token or session:{ me { platformPrivileges { generatePersonalAccessTokens manageTokens } } }If
generatePersonalAccessTokensisfalse, ask an admin to grant it. Admins manage policies at Settings > Permissions > Policies. See Policies. -
Create a token in the UI.
- Go to Settings > Access Tokens.
- Click "Generate new token".
- Choose a name and an "Expires in" duration.
- Copy the token from the "New Access Token" dialog before you close it. You can't see it again.
If the page shows the "Token based authentication is currently disabled" message, token authentication is off. Cloud customers: contact DataHub Support. Self-hosted admins: token authentication is controlled by the metadata service authentication setting. See Introducing Metadata Service Authentication. Note that
ACCESS_TOKEN_ALLOW_NO_EXPIRYandACCESS_TOKEN_ALLOWED_DURATIONSonly control which durations are allowed. They don't turn token authentication on. -
Create a token with the API (optional).
createAccessTokenrequirestype,actorUrn,name, and exactly one ofdurationordurationIso:mutation { createAccessToken(input: { type: PERSONAL actorUrn: "urn:li:corpuser:<your-user>" name: "my-token" duration: ONE_MONTH }) { accessToken metadata { urn } } }- Select
metadata { urn }. On create,expiresAtis not a field ofAccessToken. - For a custom length, use
durationIso, for exampleP30D. The default allowed values arePT1H,P1D,P7D,P30D,P90D,P180DandP365D. - To create a token for another user, you need Manage All Access Tokens and you must use the API. The UI button only works for your own token.
- For automation, use a service account. A
SERVICE_ACCOUNTtoken needs the Manage Service Accounts privilege. See Service accounts.
See Token management.
- Select
-
Use the token in API calls. Send it in the
Authorization: Bearerheader. Calls run with the privileges of the token's actor. Post to/api/graphqlon the same host you use to browse DataHub. The "New Access Token" dialog shows a ready-made curl command with that host:curl -X POST '<your DataHub URL>/api/graphql' \ -H 'Authorization: Bearer <YOUR_TOKEN>' \ -H 'Content-Type: application/json' \ -d '{"query": "{ me { corpUser { username } } }"}' -
Fix a 401 error.
- Create a new token if the old one expired or was revoked.
- Check that the header is
Authorization: Bearer <token>. - For MCP endpoints, send the token only in the
Authorization: Bearerheader. Atokenquery parameter returns 400 Bad Request. See Connecting and authenticating.