Skip to content

JARM (JWT-Secured Authorization Response Mode)

JARM wraps the entire authorization response in a signed JWT, so the RP can verify that the code/state values really came from the authorization server. Signed JARM (JWS) is supported for the query.jwt, fragment.jwt, and form_post.jwt response modes; encrypted JARM (JWE) is not — an encrypted response is rejected rather than silently accepted.

process_jarm_response verifies the response JWT end to end — signing algorithm (default-deny: none and symmetric algorithms are refused, and the algorithm must be advertised by the AS), signature against the JWKS, and the iss / aud / exp claims (all three must be present as well as valid) — then returns the same AuthorizeCallbackResponse the plain callback parser produces, ready for validate_authorize_callback_state.

from py_identity_model import (
    is_jarm_response,
    process_jarm_response,
    validate_authorize_callback_state,
)

if is_jarm_response(callback_url):
    result = process_jarm_response(
        callback_url,
        client_id=CLIENT_ID,
        disco_doc_address=DISCOVERY_URL,  # issuer, JWKS, and algorithms via discovery
    )
    # Bind the response to the original request (CSRF defense).
    validate_authorize_callback_state(result, expected_state)
    code = result.code

For form_post.jwt, the JWT arrives in the POST body rather than the URL — pass the raw JWT with is_jwt=True. To validate without any network I/O, supply issuer, jwks, and algorithms instead of disco_doc_address.

Verification failures surface as the specific exception for what went wrong: JarmValidationException for a missing response parameter, a rejected algorithm, or a missing required claim; SignatureVerificationException, InvalidIssuerException, InvalidAudienceException, or TokenExpiredException for a value that fails verification.

Detection and extraction

is_jarm_response(redirect_uri)

Return True when redirect_uri carries a JARM response parameter.

Checks the URL fragment first, then the query string (mirroring the fragment-takes-precedence rule of the plain authorization-response parser).

Parameters:

Name Type Description Default
redirect_uri str

The callback URL received from the authorization server.

required

Returns:

Type Description
bool

True if a non-empty response parameter is present.

extract_jarm_response_jwt(redirect_uri)

Extract the JARM response JWT from a callback URL.

The response value is read from the URL fragment when present, otherwise from the query string — matching where the authorization server places JARM parameters for fragment.jwt vs query.jwt.

Parameters:

Name Type Description Default
redirect_uri str

The callback URL received from the authorization server.

required

Returns:

Type Description
str

The raw (compact-serialization) response JWT.

Raises:

Type Description
JarmValidationException

If redirect_uri is not a usable string or carries no response parameter.

Sync API

process_jarm_response(response, *, client_id, disco_doc_address=None, issuer=None, jwks=None, algorithms=None, require_https=True, leeway=0, http_client=None, is_jwt=False)

Process a JARM authorization response and return the parsed callback.

Parameters:

Name Type Description Default
response str

The callback URL carrying the JARM response parameter (query.jwt / fragment.jwt), or the raw response JWT itself when is_jwt is True (form_post.jwt, where the JWT arrives in the POST body).

required
client_id str

The RP's client identifier — the expected aud claim.

required
disco_doc_address str | None

The AS discovery document URL. Required unless issuer, jwks, and algorithms are all supplied (offline mode).

None
issuer str | None

Expected issuer. In offline mode this is authoritative; in discovery mode it defaults to the discovery issuer.

None
jwks JwksResponse | None

Pre-fetched JWKS (offline mode).

None
algorithms list[str] | None

Allowed signing algorithms. In offline mode this is the allowlist; in discovery mode it overrides the AS-advertised authorization_signing_alg_values_supported when provided.

None
require_https bool

Enforce HTTPS on discovery/JWKS fetches.

True
leeway float

Clock-skew tolerance in seconds for exp.

0
http_client HTTPClient | None

Optional managed HTTP client for discovery/JWKS fetches.

None
is_jwt bool

When True, treat response as the raw response JWT rather than a callback URL to parse.

False

Returns:

Type Description
AuthorizeCallbackResponse

A parsed AuthorizeCallbackResponse. is_successful is False

AuthorizeCallbackResponse

when the response JWT carries an error claim.

Raises:

Type Description
JarmValidationException

On JARM-specific failures (no response parameter, rejected algorithm, missing mandatory claim).

TokenValidationException

(subclasses) on signature/iss/aud/exp failure.

ConfigurationException

If neither discovery nor offline inputs are fully supplied.

Async API

process_jarm_response(response, *, client_id, disco_doc_address=None, issuer=None, jwks=None, algorithms=None, require_https=True, leeway=0, http_client=None, is_jwt=False) async

Process a JARM authorization response and return the parsed callback.

Async mirror of sync.jarm.process_jarm_response — see that function for full argument and exception documentation.

Exceptions

JarmValidationException(message, details=None)

Bases: AuthorizeCallbackException

Raised when JWT-Secured Authorization Response Mode (JARM) processing fails.

Covers JARM-specific failures (JARM §4): a missing response parameter, a rejected signing algorithm (none/symmetric/not-advertised), or a response JWT missing a mandatory iss/aud/exp claim. Signature, issuer, audience, and expiry mismatches surface as the underlying TokenValidationException subclasses (SignatureVerificationException, InvalidIssuerException, InvalidAudienceException, TokenExpiredException) raised by the shared JWT decoder.

Subclasses AuthorizeCallbackException because a JARM failure is an authorization-callback processing error.