Skip to content

feat(jar): JWT-Secured Authorization Requests (JAR) support#863

Open
jd3vi1 wants to merge 2 commits into
masterfrom
feature/jar
Open

feat(jar): JWT-Secured Authorization Requests (JAR) support#863
jd3vi1 wants to merge 2 commits into
masterfrom
feature/jar

Conversation

@jd3vi1

@jd3vi1 jd3vi1 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds support for JWT-Secured Authorization Requests (JAR, RFC 9101). When requestObjectSigningKey is configured, the SDK signs all authorization parameters into a JWT and sends it as the request parameter, so the /authorize redirect carries only client_id and request.

What's included

  • requestObjectSigningKey — private key used to sign the request object. Accepts the same formats as clientAssertionSigningKey (PEM string, Buffer, KeyObject, JWK, CryptoKey).
  • requestObjectSigningAlg — required whenever requestObjectSigningKey is set. Web Crypto algorithm names are not valid JWA alg values, so an explicit JWA algorithm is required (a shared ASYMMETRIC_SIGNING_ALGS list is used, matching clientAssertionSigningAlg).
  • requestObjectSigningKeyId — optional kid header on the request object JWT.
  • Works transparently on top of the existing PAR support. When PAR is enabled, the signed request object is POSTed to /oauth/par, which is the recommended FAPI pattern.
  • The request object's aud is set to the issuer identifier advertised in the discovery document (which may differ from issuerBaseURL, e.g. a trailing slash), as JAR requires.

Usage

app.use(
  auth({
    authorizationParams: { response_type: 'code' },
    requestObjectSigningKey: fs.readFileSync('./request-object-key.pem'),
    requestObjectSigningAlg: 'RS256',
    pushedAuthorizationRequests: true, // recommended
  }),
);

Tests

  • Unit tests for buildRequestObject (header, kid, standard claims, aud), config validation (alg required with key), and the login redirect (request param present, PAR combination).
  • An end-to-end test covering the combined PAR + JAR flow.
  • Type tests in index.test-d.ts.
  • Documentation in EXAMPLES.md and a runnable example at examples/jar.js.

Comment thread examples/jar.js Dismissed
Sign authorization request parameters into a JWT and send them as the
`request` parameter (RFC 9101). Enabled by setting `requestObjectSigningKey`
with a required `requestObjectSigningAlg`. Works alongside PAR, and the
request object's `aud` is set to the discovered issuer identifier.
…ing key

Address review feedback on JAR:
- buildRequestObject now requires the discovered issuer as its audience instead
  of falling back to issuerBaseURL, which produced the invalid_request_object
  mismatch the spec warns against. Tests pass the discovered issuer explicitly.
- Reject an empty-string requestObjectSigningKey at config validation so the
  'is set' check is consistent (Joi treated '' as set while the login-side check
  skipped JAR, silently disabling it).
- Add tests: buildRequestObject throws without audience, and the non-PAR
  authorize redirect carries only client_id and request.
@jd3vi1

jd3vi1 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the nits in 7ff0457:

  1. aud fallback removed. buildRequestObject now requires the discovered issuer as its audience argument and throws if it is missing, so the issuerBaseURL fallback (the mismatch that triggers invalid_request_object) is gone. The unit tests now pass the discovered issuer explicitly and assert aud equals it.
  2. Non-PAR redirect coverage added. New test asserts the non-PAR authorize redirect carries only client_id and request.
  3. Empty-string key. requestObjectSigningKey now rejects '' at config validation, so the "is set" check is consistent between the schema and the login-side guard (previously '' forced alg required but silently skipped JAR).

Full suite and tsd green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants