Skip to content

Commit

Permalink
feat: add a helper for asserting JWT Client Auth claims and header
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Nov 21, 2024
1 parent 05f6bf4 commit 82d4e50
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ location / {
- [userinfo](#featuresuserinfo)
- [acrValues](#acrvalues)
- [allowOmittingSingleRegisteredRedirectUri](#allowomittingsingleregisteredredirecturi)
- [assertJwtClientAuthClaimsAndHeader](#assertjwtclientauthclaimsandheader)
- [claims ❗](#claims)
- [clientBasedCORS](#clientbasedcors)
- [clientDefaults](#clientdefaults)
Expand Down Expand Up @@ -2183,6 +2184,21 @@ _**default value**_:
true
```

### assertJwtClientAuthClaimsAndHeader

Helper function used to validate the JWT Client Authentication Assertion Claims Set and Header beyond what its specification mandates.


_**default value**_:
```js
async function assertJwtClientAuthClaimsAndHeader(ctx, claims, header, client) {
// @param ctx - koa request context
// @param claims - parsed JWT Client Authentication Assertion Claims Set as object
// @param header - parsed JWT Client Authentication Assertion Headers as object
// @param client - the Client instance
}
```

### claims

Describes the claims that the OpenID Provider MAY be able to supply values for.
Expand Down
15 changes: 15 additions & 0 deletions lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ async function assertClaimsParameter(ctx, claims, client) {
// @param client - the Client instance
}

async function assertJwtClientAuthClaimsAndHeader(ctx, claims, header, client) {
// @param ctx - koa request context
// @param claims - parsed JWT Client Authentication Assertion Claims Set as object
// @param header - parsed JWT Client Authentication Assertion Headers as object
// @param client - the Client instance
}

async function assertJwtClaimsAndHeader(ctx, claims, header, client) {
// @param ctx - koa request context
// @param claims - parsed Request Object JWT Claims Set as object
Expand Down Expand Up @@ -2821,6 +2828,14 @@ function makeDefaults() {
'ES256', 'EdDSA',
],
},

/**
* assertJwtClientAuthClaimsAndHeader
*
* description: Helper function used to validate the JWT Client Authentication Assertion Claims Set and Header beyond
* what its specification mandates.
*/
assertJwtClientAuthClaimsAndHeader,
};

return defaults;
Expand Down
9 changes: 8 additions & 1 deletion lib/shared/token_jwt_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import instance from '../helpers/weak_cache.js';
import * as JWT from '../helpers/jwt.js';

export default function getTokenJwtAuth(provider) {
const clockTolerance = instance(provider).configuration('clockTolerance');
const { clockTolerance, assertJwtClientAuthClaimsAndHeader } = instance(provider).configuration();
return async function tokenJwtAuth(
ctx,
keystore,
Expand Down Expand Up @@ -53,6 +53,13 @@ export default function getTokenJwtAuth(provider) {
throw new InvalidClientAuth(err.message);
}

await assertJwtClientAuthClaimsAndHeader(
ctx,
structuredClone(payload),
structuredClone(header),
ctx.oidc.client,
);

const unique = await provider.ReplayDetection.unique(
payload.iss,
payload.jti,
Expand Down

0 comments on commit 82d4e50

Please sign in to comment.