Skip to content
Trouble with OAuth 2.0 in the browser? Watch Web Security and BFF with Philippe De Ryck.

Token Introspection Endpoint

The client library for OAuth 2.0 token introspection (RFC 7662) is provided by the IntrospectionClient class, and as an extension method for HttpClient.

The following code sends a reference token to an introspection endpoint:

var clientOptions = new IntrospectionClientOptions
{
  Address = Endpoint,
  ClientId = "client",
  ClientSecret = "secret",
  ResponseFormat = ResponseFormat.Json
};

var httpClient = new HttpClient();

var introspectionClient = new IntrospectionClient(httpClient, clientOptions);
var introspectionResponse = await introspectionClient.Introspect("token");

The response of a token introspection request is an object of type TokenIntrospectionResponse. Before using the response, you should always check the IsError property to make sure the request was successful:

if (introspectionResponse.IsError) throw new Exception(introspectionResponse.Error);
var isActive = introspectionResponse.IsActive;
var claims = introspectionResponse.Claims;

The TokenIntrospectionResponse class exposes the raw response through its Raw property, and to the parsed JSON document through its Json property. In addition, it provides access to the following standard response parameters:

PropertyValue
ScopesThe list of scopes associated to the token or an empty array if no scope claim is present.
ClientIdThe client identifier for the OAuth 2.0 client that requested the token or null if the client_id claim is missing.
UserNameThe human-readable identifier for the resource owner who authorized the token or null if the username claim is missing.
TokenTypeThe type of the token as defined in section 5.1 of OAuth 2.0 (RFC6749) or null if the token_type claim is missing.
ExpirationThe expiration time of the token or null if the exp claim is missing.
IssuedAtThe issuance time of the token or null if the iat claim is missing.
NotBeforeThe validity start time of the token or null if the nbf claim is missing.
SubjectThe subject of the token or null if the sub claim is missing.
AudiencesThe service-specific list of string identifiers representing the intended audience for the token or an empty array if no aud claim is present.
IssuerThe string representing the issuer of the token or null if the iss claim is missing.
JwtIdThe string identifier for the token or null if the jti claim is missing.

Introspection requests can optionally pass a parameter to indicate that a signed JWT rather than JSON payload is desired. Such a JWT response is most often useful for non-repudiation. For example, an API might rely on the claims from introspection to produce digitally signed documents or issue certificates, with the Authorization Server assuming legal liability for the introspected data. A JWT introspection response can be stored and its signature independently verified as part of an audit.

To request the JWT response format, set the ResponseFormat option to ResponseFormat.Jwt.

var client = new HttpClient();
var introspectionResponse = await client.IntrospectTokenAsync(
new TokenIntrospectionRequest
{
Address = Endpoint,
Token = "token",
ResponseFormat = ResponseFormat.Jwt
});

By default, when the introspection endpoint returns a JWT, the system performs only a basic format check on the response. Full cryptographic validation of the JWT’s signature and claims is not performed.

This approach is generally appropriate because the introspection request is made over a direct back-channel connection from the application to the introspection endpoint. This connection is secured by TLS, which guarantees the authenticity and integrity of the response in transit. The introspected claims can safely be used immediately without an additional cryptographic validation.

An extensibility point is available to provide your own implementation of ITokenIntrospectionJwtResponseValidator.

ITokenIntrospectionJwtResponseValidator.cs
public interface ITokenIntrospectionJwtResponseValidator
{
void Validate(string rawJwtResponse);
}

A custom validator can be applied using the TokenIntrospectionRequest.JwtResponseValidator property or using IntrospectionClientOptions:

var client = new HttpClient();
var introspectionResponse = await client.IntrospectTokenAsync(
new TokenIntrospectionRequest
{
Address = Endpoint,
Token = "token",
ResponseFormat = ResponseFormat.Jwt,
JwtResponseValidator = new CustomIntrospectionJwtResponseValidator()
});