Skip to content
SupportDashboard

Tokens and Scopes

Understand OAuth2 token formats, scopes, claims, and lifecycle management

oauth2 tokens scopes jwt access token id token refresh token introspection revocation graphql hasura
Token Format Default Lifetime Description
Access Token RSA-signed JWT 15 minutes Used to access protected resources
ID Token RSA-signed JWT Same as access token Contains user identity claims (OIDC)
Refresh Token UUID 30 days Used to obtain new access and ID tokens

Access tokens are RSA-signed JWTs. The following example shows their claims:

{
"iss": "https://your-project.auth.nhost.run/v1",
"sub": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"aud": "https://your-project.nhost.run",
"client_id": "nhoa_a1b2c3d4e5f67890",
"sid": "3fb25293-8b81-44eb-b5c9-465741e54148",
"jti": "64d9576c-16a5-4c08-a38b-0ead97d3b462",
"iat": 1234567890,
"exp": 1234568790,
"scope": "openid profile email"
}
Claim Description
aud Project audience when configured; otherwise the OAuth2 client ID (unlike session tokens, OAuth2 access tokens still include aud when unset).
client_id Client to which the access token was issued. Introspection uses this claim to bind the token to the authenticated client, rather than treating the project audience as a client ID.
sid auth.oauth2_refresh_tokens.id, stable across refresh-token rotations within the OAuth2 session. This is not the refresh-token value.
jti New random UUID for each access token, including tokens obtained by refresh.

The JWT header includes typ: at+jwt (RFC 9068) and kid identifying the signing key. The signing algorithm depends on your RSA key configuration (RS256, RS384, or RS512). See Verify a JWT for how to verify tokens using the JWKS endpoint.

When the graphql scope is requested, the access token includes GraphQL-compatible claims. This allows the access token to be used directly with your GraphQL API for authorization.

{
"iss": "https://your-project.auth.nhost.run/v1",
"sub": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"aud": "https://your-project.nhost.run",
"client_id": "nhoa_a1b2c3d4e5f67890",
"sid": "3fb25293-8b81-44eb-b5c9-465741e54148",
"jti": "64d9576c-16a5-4c08-a38b-0ead97d3b462",
"iat": 1234567890,
"exp": 1234568790,
"scope": "openid profile email graphql",
"https://hasura.io/jwt/claims": {
"x-hasura-user-id": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"x-hasura-default-role": "user",
"x-hasura-allowed-roles": ["user", "me"],
"x-hasura-my-custom-claim": "custom value"
}
}

Without the graphql scope, the https://hasura.io/jwt/claims namespace is omitted from the access token.

The graphql:role:xxxx scope works like the graphql scope but narrows the claims to specific roles. This is useful when a third-party integration should only see a subset of the user’s roles.

  • The plain graphql scope acts as a superset — if a client is allowed graphql, any graphql:role:xxxx scope is implicitly permitted. The reverse is not true: having graphql:role:xxxx does not grant graphql. To restrict a client to specific roles, omit graphql and list individual graphql:role:xxxx scopes.
  • Multiple graphql:role:xxxx scopes can be requested in a single authorization. The first becomes x-hasura-default-role and all of them become x-hasura-allowed-roles.
  • The graphql and graphql:role:xxxx scopes are mutually exclusive in a single request. A client may have both in its allowed scopes, but a request cannot use both at once.
  • At token time, every requested role must exist in the user’s allowed roles. If the user lacks a requested role, the token exchange fails with access_denied.
  • On refresh, the original graphql:role:xxxx scopes are preserved and roles are re-validated against the user’s current roles. If the user has lost a requested role since the original authorization, the refresh fails with access_denied.

Example: a client with scopes: ["openid", "graphql:role:viewer"] requesting scope=openid graphql:role:viewer produces:

{
"iss": "https://your-project.auth.nhost.run/v1",
"sub": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"aud": "https://your-project.nhost.run",
"client_id": "nhoa_a1b2c3d4e5f67890",
"sid": "3fb25293-8b81-44eb-b5c9-465741e54148",
"jti": "64d9576c-16a5-4c08-a38b-0ead97d3b462",
"iat": 1234567890,
"exp": 1234568790,
"scope": "openid graphql:role:viewer",
"https://hasura.io/jwt/claims": {
"x-hasura-user-id": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"x-hasura-default-role": "viewer",
"x-hasura-allowed-roles": ["viewer"]
}
}

With multiple roles (scope=openid graphql:role:viewer graphql:role:editor):

{
"https://hasura.io/jwt/claims": {
"x-hasura-user-id": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"x-hasura-default-role": "viewer",
"x-hasura-allowed-roles": ["viewer", "editor"]
}
}

The ID token is issued when the openid scope is requested. It contains identity claims about the authenticated user, controlled by the scopes granted:

Claim Description
iss Issuer URL
sub User UUID
aud Client ID
iat Issued at timestamp
exp Expiration timestamp
auth_time When the user authenticated
at_hash Access token hash (when access token is issued alongside)
Scope Claims Condition
profile name, picture, locale Only if the user has these values set
email email, email_verified Only if the user has an email
phone phone_number, phone_number_verified Only if the user has a phone number

The nonce claim is included in the ID token if a nonce parameter was provided in the authorization request. It is not included on refresh.

The ID token’s JWT header includes typ: JWT, and its aud claim identifies the OAuth2 client. ID tokens do not include client_id, sid, or jti. The ID token identifies the signed-in user to that client; it must not be used as a bearer access token for resource APIs.

The UserInfo endpoint returns user claims filtered by the scopes of the access token.

const { body: userinfo } = await nhost.auth.oauth2UserinfoGet({
headers: { Authorization: `Bearer ${accessToken}` },
});

Example response (with openid profile email scopes):

{
"sub": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"name": "Jane Doe",
"picture": "https://www.gravatar.com/avatar/...",
"locale": "en",
"email": "jane@example.com",
"email_verified": true
}

When the graphql or graphql:role:xxxx scope is present, the UserInfo response also includes the GraphQL claims namespace with roles and any custom claims. With graphql:role:xxxx, the roles are narrowed the same way as in the access token. Unlike the access token (where session-variable values are string-encoded), the UserInfo endpoint returns proper JSON types — arrays as JSON arrays, booleans as booleans, etc. This makes it suitable for third-party OIDC consumers (e.g. Grafana) that read user attributes from the UserInfo endpoint.

Example response (with openid profile graphql scopes):

{
"sub": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"name": "Jane Doe",
"picture": "https://www.gravatar.com/avatar/...",
"locale": "en",
"https://hasura.io/jwt/claims": {
"x-hasura-user-id": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"x-hasura-default-role": "user",
"x-hasura-allowed-roles": ["user", "me"],
"x-hasura-user-is-anonymous": false,
"x-hasura-organization-ids": ["org-1", "org-2"]
}
}

Both GET and POST methods are supported, per the OIDC specification.

Refresh tokens are UUID strings (not JWTs). They implement token rotation: each time a refresh token is used, its stored hash is replaced and a new token is issued. The refresh-token row (and hence sid) stays the same, and the new token inherits the original scopes.

const { body: tokens } = await nhost.auth.oauth2Token({
grant_type: 'refresh_token',
refresh_token: currentRefreshToken,
client_id: clientId,
client_secret: clientSecret, // required for confidential clients
});
// tokens.refresh_token is a NEW token — the old one is now invalid

The response format is the same as the initial token exchange — it includes a new access token, ID token (if openid scope), and refresh token.

Check whether a token is active by calling the introspection endpoint. Client authentication is required.

const { body: result } = await nhost.auth.oauth2Introspect({
token: tokenToCheck,
token_type_hint: 'access_token', // or 'refresh_token'
client_id: clientId,
client_secret: clientSecret, // required for confidential clients
});

Active token response:

{
"active": true,
"sub": "f5765cb0-1c45-4b6e-8a30-0b2abc1a2f3d",
"client_id": "nhoa_a1b2c3d4e5f67890",
"aud": ["https://your-project.nhost.run"],
"sid": "3fb25293-8b81-44eb-b5c9-465741e54148",
"jti": "64d9576c-16a5-4c08-a38b-0ead97d3b462",
"scope": "openid profile email",
"exp": 1234568790,
"iat": 1234567890,
"iss": "https://your-project.auth.nhost.run/v1",
"token_type": "access_token"
}

For active access tokens, aud is returned as an array, and sid/jti are returned when present. sid is an Nhost extension to the introspection response. The response’s client_id identifies the authenticated client bound to the token, not the project aud. For pre-change access tokens without a client_id claim, introspection instead requires aud to contain the authenticated client’s ID. For active refresh tokens, sid is the stored refresh-token row ID; aud and jti are omitted. Older access tokens may omit these fields. Inactive results contain only active: false.

Inactive token response:

{
"active": false
}

Revoke a refresh token to immediately invalidate it. The endpoint always returns 200 OK regardless of whether the token existed, per the RFC 7009 security recommendation.

await nhost.auth.oauth2Revoke({
token: refreshToken,
token_type_hint: 'refresh_token',
client_id: clientId,
client_secret: clientSecret, // required for confidential clients
});