Tokens

1. Overview

When using the OAuth2 and OpenID Connect authentication grants you’ll be dealing with some tokens. We’ll review each token type, the purpose and how to use them.

2. Access Token

The access token is an opaque token per the OAuth2 specification. In the FusionAuth implementation the access token is a JSON Web Token (JWT).

Table 1. Access Token Claims

applicationId [UUID]

The unique Id of the Application for which the User has been authenticated. A JWT can only represent authorization to a single Application.

This claim is only present if the User has a registration to the Application.

To obtain a JWT for another Application you must either authenticate again with a different applicationId using the Authentication API or utilize the Issue a JWT API to exchange a valid JWT for another.

aud [String]

The audience the JWT is intended for. This registered claim is defined by RFC 7519 Section 4.1.3

This claim will be equal to the client_id.

authenticationType [String]

The method used to authenticate the User which resulted in this JWT being generated. The possible values are:

  • APPLICATION_TOKEN - The User was authenticated using an Application Authentication Token.

  • FEDERATED_JWT - The User was authenticated using a JWT from an external Identity Provider.

  • JWT_SSO - A valid JWT authorized to one Application was exchanged for another JWT authorized to a different Application.

  • ONE_TIME_PASSWORD The User was authenticated using a one time password.   Available Since 1.5.0

  • PASSWORD - The User was authenticated using a loginId and password combination.

  • PASSWORDLESS - The user was authenticated using a passwordless login link.   Available Since 1.5.0

  • REFRESH_TOKEN - The User requested a new JWT using a Refresh Token.

  • FACEBOOK - The User was authenticated using Facebook.   Available Since 1.1.0

  • GOOGLE - The User was authenticated using Google. Available Since 1.1.0

  • TWITTER - The User was authenticated using Twitter. Available Since 1.1.0

  • OPENID_CONNECT - The User was authenticated using an external OpenID Connect provider. Available Since 1.1.0

email [String]

The email address of the User whose claims are represented by this JWT.

email_verified [Boolean]

The OpenId Connect claim indicating if the User’s email has been verified.

exp [Long]

The expiration instant of the JWT expressed as UNIX time which is the number of seconds since Epoch. This registered claim is defined by RFC 7519 Section 4.1.4

iat [Long]

The instant that the JWT was issued expressed as UNIX time which is the number of seconds since Epoch. This registered claim is defined by RFC 7519 Section 4.1.6

iss [String]

The issuer of the JWT. For FusionAuth, this is always the value defined in the global JWT configuration. This registered claim is defined by RFC 7519 Section 4.1.1

preferred_username [String] Available Since 1.5.0

The username of the User who claims are represented by this JWT.

roles [Array<String>]

The roles assigned to the User in the authenticated Application. This claim is only present if the User has a registration to the Application.

sub [UUID]

The subject of the access token. This value is equal to the User’s unique Id in FusionAuth. This registered claim is defined by RFC 7519 Section 4.1.2

3. Id Token

The Id Token is part of the OpenID Connect specification. The Id Token is a JSON Web Token (JWT) per the OpenID Connect specification. The Id Token is similar to the access token in the FusionAuth implementation. The Id Token may contain additional claims not present in the Access Token.

The Id Token may be returned as part of an Authentication request when the openid scope is requested.

Table 2. Id Token Claims

applicationId [UUID]

The unique Id of the Application for which the User has been authenticated. A JWT can only represent authorization to a single Application.

This claim is only present if the User has a registration to the Application.

To obtain a JWT for another Application you must either authenticate again with a different applicationId using the Authentication API or utilize the Issue a JWT API to exchange a valid JWT for another.

at_hash [String] Available Since 1.5.0

The Access Token hash value. As defined by the 3.1.3.6 of the OpenID Connect Core specification this value is a base64 encoded hash of the access token.

aud [String]

The audience the JWT is intended for. This registered claim is defined by RFC 7519 Section 4.1.3

This claim will be equal to the client_id.

authenticationType [String]

The method used to authenticate the User which resulted in this JWT being generated. The possible values are:

  • APPLICATION_TOKEN - The User was authenticated using an Application Authentication Token.

  • FEDERATED_JWT - The User was authenticated using a JWT from an external Identity Provider.

  • JWT_SSO - A valid JWT authorized to one Application was exchanged for another JWT authorized to a different Application.

  • ONE_TIME_PASSWORD The User was authenticated using a one time password.   Available Since 1.5.0

  • PASSWORD - The User was authenticated using a loginId and password combination.

  • PASSWORDLESS - The user was authenticated using a passwordless login link.   Available Since 1.5.0

  • REFRESH_TOKEN - The User requested a new JWT using a Refresh Token.

  • FACEBOOK - The User was authenticated using Facebook.   Available Since 1.1.0

  • GOOGLE - The User was authenticated using Google. Available Since 1.1.0

  • TWITTER - The User was authenticated using Twitter. Available Since 1.1.0

  • OPENID_CONNECT - The User was authenticated using an external OpenID Connect provider. Available Since 1.1.0

c_hash [String] Available Since 1.5.0

The Access Token hash value. As defined by the 3.3.2.11 of the OpenID Connect Core specification this value is a base64 encoded hash of the authorization code.

email [String]

The email address of the User whose claims are represented by this JWT.

email_verified [Boolean]

The OpenId Connect claim indicating if the User’s email has been verified.

exp [Long]

The expiration instant of the JWT expressed as UNIX time which is the number of seconds since Epoch. This registered claim is defined by RFC 7519 Section 4.1.4

iat [Long]

The instant that the JWT was issued expressed as UNIX time which is the number of seconds since Epoch. This registered claim is defined by RFC 7519 Section 4.1.6

iss [String]

The issuer of the JWT. For FusionAuth, this is always the value defined in the global JWT configuration. This registered claim is defined by RFC 7519 Section 4.1.1

nonce [String] Available Since 1.5.0

preferred_username [String] Available Since 1.5.0

The username of the User who claims are represented by this JWT.

roles [Array<String>]

The roles assigned to the User in the authenticated Application. This claim is only present if the User has a registration to the Application.

sub [UUID]

The subject of the access token. This value is equal to the User’s unique Id in FusionAuth. This registered claim is defined by RFC 7519 Section 4.1.2

4. Refresh Token

The refresh token is an opaque token that is used to "refresh", or obtain a new access token. Because the life of an access token is generally measured in minutes, the Refresh Token is by comparison a long lived token that can be used to maintain access to a protected resource.

To request a refresh token during authentication you must provide the offline_access scope. The refresh token is not supported by the Implicit Grant, so if you provide the offline_access scope during an Implicit Grant workflow it will be ignored.

If you request the offline_access scope and an Refresh Token is not returned, ensure that the FusionAuth application has been configured to generate refresh tokens. Ensure Generate refresh tokens is enabled in your application settings. See Settings Applications OAuth. This setting will cause a Refresh Token to be returned when the offline_access scope is requested. You will also want to ensure the Refresh Token grant is enabled which allows the use of the Refresh Token to be exchanged for a new Access Token.