You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 30277ae
Browse filesBrowse the repository at this point in the historyBrowse files
feat(jwt,jwk): add a configurable WWW-Authenticate realm (#5141)
* feat(jwt): add a realm option and escape challenge values
The 401 challenge hardcoded `ctx.req.url` as the `realm`. RFC 6750 describes
realm as a stable, human-readable name for the protection space, so reflecting
the full URL produces a different realm for every path and query string.
bearer-auth already exposes a `realm` option; jwt had no equivalent and its
`unauthorizedResponse()` helper is private, leaving no way to override it.
`realm` and `error_description` are also interpolated into a quoted-string
without escaping, so a `"` in either truncates the header. Both are now escaped
the way bearer-auth does it.
The default is unchanged to stay backward compatible.
Refs #4989
* feat(jwk): add a realm option and escape challenge values
Mirrors the preceding jwt change; jwk carries an identical copy of
`unauthorizedResponse()` with the same hardcoded realm and unescaped
interpolation.
Refs #4989
* test(jwt,jwk): cover realm configuration and quote escaping
Asserts the configured realm reaches the WWW-Authenticate header for both the
missing-credentials and invalid-token paths, that embedded double quotes are
escaped, and that the default is still the request URL.
The realm and escaping cases fail without the preceding commits; the default
cases guard against regressing existing behavior.
* add a test
---------
Co-authored-by: Yusuke Wada <[email protected]>
'Bearer realm="http://localhost/auth/page?a=1",error="invalid_request",error_description="no authorization included in request"'
Copy file name to clipboardExpand all lines: src/middleware/jwk/jwk.ts
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ import type { VerifyOptions } from '../../utils/jwt/jwt'
25
25
* @param {boolean} [options.allow_anon] - If set to `true`, the middleware allows requests without a token to proceed without authentication.
26
26
* @param {string} [options.cookie] - If set, the middleware attempts to retrieve the token from a cookie with these options (optionally signed) only if no token is found in the header.
27
27
* @param {string} [options.headerName='Authorization'] - The name of the header to look for the JWT token. Default is 'Authorization'.
28
+
* @param {string} [options.realm] - The protection space described by the `realm` parameter of the returned `WWW-Authenticate` challenge header. Defaults to the request URL.
28
29
* @param {AsymmetricAlgorithm[]} options.alg - An array of allowed asymmetric algorithms for JWT verification. Only tokens signed with these algorithms will be accepted.
29
30
* @param {RequestInit} [init] - Optional init options for the `fetch` request when retrieving JWKS from a URI.
'Bearer realm="http://localhost/auth/page?a=1",error="invalid_request",error_description="no authorization included in request"'
* @param {string} [options.cookie] - If this value is set, then the value is retrieved from the cookie header using that value as a key, which is then validated as a token.
30
30
* @param {SignatureAlgorithm} options.alg - An algorithm type that is used for verifying (required). Available types are `HS256` | `HS384` | `HS512` | `RS256` | `RS384` | `RS512` | `PS256` | `PS384` | `PS512` | `ES256` | `ES384` | `ES512` | `EdDSA`.
31
31
* @param {string} [options.headerName='Authorization'] - The name of the header to look for the JWT token. Default is 'Authorization'.
32
+
* @param {string} [options.realm] - The protection space described by the `realm` parameter of the returned `WWW-Authenticate` challenge header. Defaults to the request URL.
0 commit comments