What the subject is
The subject is the identifier of the end-user (the resource owner) on whose behalf a code or token is issued. Your authorization server generates the subject and passes it to the Authlete API as thesubject request parameter.
First, your authorization server passes the subject to Authlete after user authentication, and Authlete binds the subject it receives to the code and tokens it issues (Figure 1).
Figure 1: Binding the subject after user authentication
Figure 2: Returning the subject inside tokens
Figure 3: Returning the subject as the result of token introspection
Relationship to the OAuth/OIDC specifications
Authlete’s subject corresponds tosub in the following elements of the OAuth/OIDC specifications:
OpenID Connect Core 1.0, Section 5.7 names
sub and iss together as the only claims a client can rely on as a stable identifier for the end-user, and says that email, phone_number and preferred_username must not be used as one. Because sub is never reassigned, a client can store it against the user account it manages and recognize the same user on later logins.
Your authorization server generates an end-user identifier with these properties and passes it to Authlete as the subject request parameter. Authlete emits the value it receives as the sub of the elements above.
Division of responsibilities
The subject is divided between your authorization server and Authlete as follows.Authorization server
- Establishes who the end-user is. Authlete is not involved in this step. The authorization server may authenticate the user itself (a login form, passkeys), rely on an existing session, or accept an authentication result from an external identity provider through federation.
- Determines the subject that represents that user. Use a value that satisfies the properties above: something that never changes and is never reused, such as an internal account ID. An e-mail address or a display name does not qualify, because it can change. When authentication is delegated to an external identity provider, map its result to your own account identifier rather than forwarding the provider’s identifier as it is: it is unique and stable within that provider, not necessarily within your issuer.
- Passes the subject to an issuing API (e.g. Issue Authorization Response). Any other information about the user that an ID token or UserInfo response should carry is passed as claims. Authlete has no user store and derives nothing from the subject.
Authlete
-
Checks the format of the subject. Issue Authorization Response in Authlete 3.0 checks the following requirements (the other issuing APIs apply the same length limit):
- Binds the subject to the authorization code and tokens it issues.
-
Returns the subject in tokens and API responses. Authlete emits it as the
subclaim of ID tokens, thesubof UserInfo responses, thesubof JWT access tokens, thesubmember of standard introspection responses, and thesubjectfield of its own introspection API (see the following sections).
How the subject flows
Sent by the authorization server
Once it has identified the end-user, your authorization server sends a request containing the subject to an issuing (flow-completing) API:Returned by Authlete
The subject passed to Authlete appears in the following tokens and responses:- Access tokens are bound to the subject, which comes back as the result of token introspection and as a value carried in JWT access tokens.
- Introspection: Process Introspection Request returns it as
subject, and Process OAuth 2.0 Introspection Request returns it as the RFC 7662submember, so a resource server can tell whose token it received. - JWT access tokens: carry it as
sub. Authlete’s JWT access tokens use the claim names of RFC 9068 but do not conform to that profile; see the “JWT Access Token” section of JWTs in OAuth and OpenID Connect. - A token issued by the client credentials grant has no subject: standard introspection omits
sub, and a JWT access token carries"sub": null.
- Introspection: Process Introspection Request returns it as
- ID tokens carry the subject as the
subclaim.- Issue Authorization Response, Complete Device Authorization and Complete Backchannel Authentication also accept a
subrequest parameter, which sets a value other than the subject (the access token stays bound to the subject). This keeps the actual subject hidden from client applications. See Adding Claims to ID Token.
- Issue Authorization Response, Complete Device Authorization and Complete Backchannel Authentication also accept a
- UserInfo responses, like ID tokens, carry the subject as the
subclaim.- Likewise, the
subparameter of Issue UserInfo Response sets a value other than the subject.
- Likewise, the
Working with tokens by subject
Once a subject is bound to a token, the following APIs and settings use the subject to work with that end-user’s tokens:- Process Introspection Request takes
subjectas an optional parameter. When it is given and does not match the subject bound to the access token, Authlete returnsaction=FORBIDDEN, so a resource server can require that a token belong to a specific user. - List Issued Tokens filters issued tokens by subject.
- Single Access Token Per Subject keeps only the newest access token valid for each subject.
Handling pairwise subject identifiers
What pairwise subject identifiers are
OpenID Connect Core defines two subject identifier types for thesub claim:
The specification does not define how a pairwise subject identifier is derived. It does require that the provider calculate a unique
sub for each sector identifier and that the value not be reversible by any party other than the provider (Section 8.1).
What Authlete does
Given an identifier that is unique within your authorization server, Authlete derives the per-clientsub value as follows.
This applies to a client whose subject identifier type is
pairwise, when no sub parameter is given.- Determine the client’s sector identifier. It is the host of the client’s
sector_identifier_uriif one is registered, otherwise the host shared by all of its redirect URIs. If the client has neither asector_identifier_urinor a single redirect URI host, no sector identifier can be derived, and Authlete uses the subject assubunchanged. - Determine the
subvalue. Authlete computes a hash from the sector identifier, the service, the subject and other inputs, and uses it assub, encoded in URL-safe Base64 without padding (a 43-character string). The same user therefore always gets the samesubat the same client (and at other clients in the same sector), while different clients and different services get different values.
sub of ID tokens from every flow (including CIBA, the device flow, ID token reissuance and Native SSO), of UserInfo responses and of logout tokens. The access token, on the other hand, stays bound to the subject your authorization server passed, so introspection’s subject and a JWT access token’s sub return that value.
Pairwise subject identifiers are supported by Authlete 2.2 and later.
Configuration
The subject identifier type is set per client: Subject Type (subjectType, PUBLIC or PAIRWISE) in the client settings. For a pairwise client whose redirect URIs span more than one host, also register Sector Identifier URI (sectorIdentifierUri), or Authlete cannot derive a sector identifier and falls back to the public behavior.