Skip to content

Commit

Permalink
feat: add a helper allowing custom claims parameter validations
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jan 16, 2024
1 parent 53babe6 commit ec2a1f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
20 changes: 20 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,30 @@ Enables the use and validations of `claims` parameter as described in the specif
_**default value**_:
```js
{
assertClaimsParameter: [AsyncFunction: assertClaimsParameter], // see expanded details below
enabled: false
}
```

<details><summary>(Click to expand) features.claimsParameter options details</summary><br>


#### assertClaimsParameter

Helper function used to validate the claims parameter beyond what the OpenID Connect 1.0 specification requires.


_**default value**_:
```js
async function assertClaimsParameter(ctx, claims, client) {
// @param ctx - koa request context
// @param claims - parsed claims parameter
// @param client - the Client instance
}
```

</details>

### features.clientCredentials

[`RFC6749`](https://www.rfc-editor.org/rfc/rfc6749.html#section-1.3.4) - Client Credentials
Expand Down
8 changes: 7 additions & 1 deletion lib/actions/authorization/check_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import isPlainObject from '../../helpers/_/is_plain_object.js';
*
* Merges requested claims with acr as requested if acr_values is provided
*/
export default function checkClaims(ctx, next) {
export default async function checkClaims(ctx, next) {
const { params } = ctx.oidc;

if (params.claims !== undefined) {
Expand Down Expand Up @@ -55,6 +55,12 @@ export default function checkClaims(ctx, next) {
if (params.response_type === 'id_token' && claims.userinfo) {
throw new InvalidRequest('claims.userinfo should not be used if access_token is not issued');
}

await claimsParameter.assertClaimsParameter?.(
ctx,
claims,
ctx.oidc.client,
);
}
}

Expand Down
17 changes: 16 additions & 1 deletion lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ async function triggerAuthenticationDevice(ctx, request, account, client) {
throw new Error('features.ciba.triggerAuthenticationDevice not implemented');
}

async function assertClaimsParameter(ctx, claims, client) {
// @param ctx - koa request context
// @param claims - parsed claims parameter
// @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 @@ -1153,7 +1159,16 @@ function makeDefaults() {
* specification.
*
*/
claimsParameter: { enabled: false },
claimsParameter: {
enabled: false,

/**
* features.claimsParameter.assertClaimsParameter
*
* description: Helper function used to validate the claims parameter beyond what the OpenID Connect 1.0 specification requires.
*/
assertClaimsParameter,
},

/*
* features.clientCredentials
Expand Down

0 comments on commit ec2a1f5

Please sign in to comment.