Skip to main content
This page is for Authlete 3.0. For 2.x, see this page.

Introduction

RFC 8693 OAuth 2.0 Token Exchange (hereinafter “Token Exchange”) is a technical standard that defines a way to get a new token by presenting an existing token and optionally one more existing token at the token endpoint. The specification is very flexible. To put it the other way around, the specification does not define details that are necessary for secure token exchange. Therefore, you have to consider further details in the undefined part to implement the specification in an authorization server. This article describes some key details to implement the Token Exchange specification and Authlete’s support of this specification.

Specification

The diagram below illustrates the token exchange flow. Token Exchange The following sections explain token types and token exchange request/response.

Tokens

There are two kinds of input tokens; a subject token and an actor token.

Subject Token

“Subject Token” is a mandatory input token. It “represents the identity of the party on behalf of whom the request is being made.” (excerpt from Section 2.1. Request of RFC 8693) The specification expects that the subject identified by the subject token is used as the subject of the newly issued token.

Actor Token

“Actor Token” is an optional input token. It “represents the identity of the acting party.” (excerpt from Section 2.1. Request of RFC 8693) If there is a need to distinguish the subject of the newly issued token from the acting party that uses the token, authorization server implementations may utilize the actor token and embed information about the acting party in the token to issue. Section 4.1 and Section 4.4 of RFC 8693 define JWT claims related to the acting party.

Token Types

As possible types of the tokens above, the specification lists the following token types and assigns token type identifiers to them. The identifiers of token types are registered at OAuth URI of OAuth Parameters of IANA (Internet Assigned Numbers Authority).
The token type identifier for JWT is defined in RFC 7519 JSON Web Token (JWT). Others are defined in RFC 8693 OAuth 2.0 Token Exchange.

Token Exchange Request

A token exchange request is a kind of token requests.

Grant Type

To distinguish token exchange requests from other token requests, a new grant type urn:ietf:params:oauth:grant-type:token-exchange is defined in the specification. The value is used as the value of the grant_type request parameter of a token request.

Client Identification and Authentication

The specification does not require client authentication and even client identification at the token endpoint. Section 2.1. Request of RFC 8693 states it as follows.
The supported methods of client authentication and whether or not to allow unauthenticated or unidentified clients are deployment decisions that are at the discretion of the authorization server.
Technically speaking, “unauthenticated clients” means public clients (cf. RFC 6749 Section 2.1. Client Types) and “unidentified clients” means that a token request does not contain information whereby to identify the client making the request. Although Appendix 1.1 of RFC 8693 shows an example of token exchange request from an unidentified client, such cases are appropriate only in limited conditions, such as a closed network within a service. In other circumstances, you have to define further details, which are out of the scope of RFC 8693, for secure token exchange.

Request Parameters

The following table shows parameters related to token exchange requests.
RFC 6749 The OAuth 2.0 Authorization Framework states “Request and response parameters MUST NOT be included more than once.” The resource request parameter and audience request parameter are exceptions.

Token Exchange Response

A token exchange response is a kind of token responses.

Response Parameters

The following table shows parameters related to token exchange responses.

Support in Authlete

This section describes Authlete’s support for Token Exchange. RFC 8693 is supported by Authlete 2.3 onwards.

Token Exchange Request

”action” value of /auth/token API response

On receiving a token request from a client, an authorization server will send the request content to Authlete’s /auth/token API as one of request parameters. This API will make a response that includes TOKEN_EXCHANGE as a value of action parameter if the following conditions are met:
  • The value of the grant_type request parameter of the token request is urn:ietf:params:oauth:grant-type:token-exchange
  • The request passes basic validation steps which are performed on Authlete server side
The following table lists response parameters related to Token Exchange in a response from the /auth/token API.

Token Validation

Regarding validation on input tokens, the specification states as follows.
In processing the request, the authorization server MUST perform the appropriate validation procedures for the indicated token type and, if the actor token is present, also perform the appropriate validation procedures for its indicated token type. The validity criteria and details of any particular token are beyond the scope of this document and are specific to the respective type of token and its content.
It means that an authorization server MUST perform an appropriate validation, but the RFC 8693 doesn’t define any details about token validation and leaves them to authorization server implementations. To reduce the burden of authorization servers, Authlete’s /auth/token API performs the following validation. Furthermore, Authlete performs additional validation on the tokens specified by the subject_token request parameter and the actor_token request parameter according to their respective token types as shown below.

Token type: JWT

Authlete does not validate an encrypted JWT because there is no standard way to obtain the key to decrypt the JWT with. This means that you must validate an encrypted JWT by yourself when one is used as an input token with the token type urn:ietf:params:oauth:token-type:jwt (if tokenExchangeEncryptedJwtRejected of your service is false).
Authlete does not verify the signature of the JWT because there is no standard way to obtain the key to verify the signature of a JWT with. This means that you must verify the signature by yourself when a signed JWT is used as an input token with the token type urn:ietf:params:oauth:token-type:jwt.

Token type: Access Token

The validation steps above imply that access tokens issued by other systems cannot be used as a subject token or an actor token with the token type urn:ietf:params:oauth:token-type:access_token. Authlete may provide a configuration option to disable the validation steps in the future, but it is not planned at the time of this writing.

Token type: Refresh Token

The validation steps above imply that refresh tokens issued by other systems cannot be used as a subject token or an actor token with the token type urn:ietf:params:oauth:token-type:refresh_token. Authlete may provide a configuration option to disable the validation steps in the future, but it is not planned at the time of this writing.

Token type: ID Token

Authlete does not validate an encrypted ID Token because there is no standard way to obtain the key to decrypt the ID Token with in the context of token exchange where the client ID for the encrypted ID Token cannot be determined. This means that you must validate an encrypted ID Token by yourself when one is used as an input token with the token type urn:ietf:params:oauth:token-type:id_token (if tokenExchangeEncryptedJwtRejected of your service is false).
The 10th validation step above implies that ID Tokens whose signature algorithm is symmetric (HS256, HS384 or HS512) cannot be used as a subject token or an actor token with the token type urn:ietf:params:oauth:token-type:id_token. It is because the symmetric key to verify the signature with (i.e. a client secret) cannot be determined in the context of token exchange.
Signature verification is performed even in the case where the issuer of the ID Token is not your service. But in that case, the issuer must support the discovery endpoint defined in OpenID Connect Discovery 1.0. Otherwise, signature verification fails.

Token type: SAML 1.1 Assertion

Token type: SAML 2.0 Assertion

Token Exchange Response

/auth/token/create API

The authorization server performs necessary validation based on the response from the /auth/token API to determine what kind of token is issued, and make a token exchange response to the client. The server uses Authlete’s /auth/token/create API to create the token exchange response, by specifying TOKEN_EXCHANGE as a value of grantType, which is one of request parameters to the API.

Configuring Token Exchange

To configure Token Exchange in Authlete, follow these steps:

Service Configuration

  1. Log in to the Authlete Management Console.
  2. Navigate to Service Settings.
  3. Go to Endpoints > Global Settings > Supported Grant Types and enable TOKEN_EXCHANGE grant.
  4. Go to Tokens and Claims > Advanced > Token Exchange.
  5. Review and enable any necessary flags to tighten the security of your Token Exchange configuration.
  6. Click Save Changes to apply the configuration.
To ensure secure token exchange, you need to define additional configurations outside the scope of RFC 8693. Authlete provides the following options for this purpose:

Client Configuration

  1. Navigate to Client Settings of your desired client.
  2. Go to Tokens and Claims > Advanced > Token Exchange.
  3. Enable Explicit Permission for Token Exchange to grant this client explicit permission to perform token exchange requests. This setting ensures that only authorized clients can perform token exchanges, especially when the service is configured to restrict token exchange to permitted clients.
  4. Click Save Changes to finalize the configuration.

Examples

Authorization Server Implementation

Processing the TOKEN_EXCHANGE Action

Authorization server implementations have to process the TOKEN_EXCHANGE action to support Token Exchange. The switch statement below excerpted from TokenRequestHandler.java in the authlete-java-jaxrs library is an example of processing the TOKEN_EXCHANGE action. The switch statement has a case entry for TOKEN_EXCHANGE.

Processing token exchange requests

TokenExchanger.java in java-oauth-server, an open-source sample implementation of authorization server written in Java, is a sample implementation of processing a token exchange request. Note that the implementation is just an example, and not intended for production use.

Request and Response Example

1. Prepare an ID Token in some way or other.

2. Make a token exchange request.

3. Receive a token exchange response.