Skip to content

Self-contained Access Tokens

Access tokens are credentials used to access protected resources. Typically, an access token is a string representing an authorization issued to the client. The string is usually opaque to the client.

The OAuth 2.0 specification does not mandate any particular implementation for access tokens but it mentions two possible strategies.

  1. The access token is an identifier that is hard to guess. For example, a randomly generated string of sufficient length, that the server handling the protected resource can use to lookup the associated authorization information.
  2. The access token self-contains the authorization information in a manner that can be verified. For example, by encoding authorization information along with a signature into the token.

So by default, a UUID is issued as an access token in WSO2 Identity Server, which is of the first type above. But, it also can be configured to issue a self-contained access token, which is of the second type above.

Why do we need self-contained access tokens?

When short string identifiers are used as access tokens, a network request to the Authorization server is required to retrieve the authorization information associated with each access token. But with self-contained access tokens there is no need for a network call to retrieve the authorization information, as it’s self-contained. Thus, access token processing may be significantly quicker and more efficient. However, when it comes to token revocation self-contained access tokens lag, whereas access tokens with string identifiers can be revoked with almost immediate effect. The common practice is to have a short expiration time with self-contained access tokens, but that may result in more refresh token requests at the Authorization server.

Configuring WSO2 Identity Server to issue self-contained access tokens

WSO2 Identity Server needs to be configured to issue above explained self-contained JWT access tokens as below.

  1. Add the following configuration property to the deployment.toml file in the <IS_HOME>/repository/conf folder.

    access_token_type= "self_contained"

  2. Restart the server.

  3. Configure an OAuth service provider.
  4. Initiate an access token request to the WSO2 Identity Server, over a known grant type. For example, the following cURL command illustrates the syntax of an access token request that can be initiated over the Resource Owner Password Credential grant type.

    cURL command
    • Navigate to your service provider, expand Inbound Authenitcaion Configurations and expand OAuth/OpenID Connect Configuration.
      • Copy the OAuth Client Key as the value for <CLIENT_ID> .
      • Copy the OAuth Client Secret as the value for <CLIENT_SECRET> .
    • Enter the username and password of the user you want to get the token as the value for <USERNAME> and <PASSWORD> respectively.
    • By default, <IS_HOST> is localhost. However, if you are using a public IP, the respective IP address or domain needs to be specified.
    • By default, <IS_HTTPS_PORT> has been set to 9443. However, if the port offset has been incremented by n , the default port value needs to be incremented by n .



    In response, the self-contained JWT access token will be returned as shown below.

    The access token you receive is a signed JSON Web Token (JWT) . Use a JWT decoder to decode the access token and you are able to see the payload of the token that includes the following JWT claims:

    Claim Name Type Claim Value
    iss string The issuer of the JWT. The ' Identity Provider Entity Id ' value of the OAuth2/OpenID Connect Inbound Authentication configuration of the Resident Identity Provider is returned here.
    aud string array The token audience list. The client identifier of the OAuth clients that the JWT is intended for, is sent herewith.
    azp string The autorized party for which the token is issued to. The client identifier of the OAuth client that the token is issued for, is sent herewith.
    iat integer The token issue time.
    exp integer The token expiration time.
    jti string Unique identifier for the JWT token.

    In addition, a user claims can be obtained by an authorized user over this JWT as per OpenID Connect claim configurations, by configuring requested user claims in the OAuth service provider. After configuring the service provider you can run the cURL command given below by providing the required details.