Skip to content

Commit

Permalink
refactor: renamed extraAccessTokenClaims helper function
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `extraAccessTokenClaims` helper function is renamed to
`extraTokenClaims`.
  • Loading branch information
panva committed Apr 1, 2020
1 parent e959b7e commit ce57d6d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
56 changes: 28 additions & 28 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ location / {
- [cookies](#cookies)
- [discovery](#discovery)
- [expiresWithSession](#expireswithsession)
- [extraAccessTokenClaims](#extraaccesstokenclaims)
- [extraTokenClaims](#extratokenclaims)
- [extraClientMetadata](#extraclientmetadata)
- [extraParams](#extraparams)
- [formats](#formats)
Expand Down Expand Up @@ -2152,32 +2152,6 @@ async function expiresWithSession(ctx, token) {
}
```

### extraAccessTokenClaims

Function used to get additional access token claims when it is being issued. These claims will be available in your storage under property `extra`, returned by introspection as top level claims and pushed into `jwt`, and `jwt-ietf` formatted tokens as top level claims as well. Returned claims may not overwrite other top level claims.



_**default value**_:
```js
async function extraAccessTokenClaims(ctx, token) {
return undefined;
}
```
<a id="extra-access-token-claims-to-push-additional-claims-to-an-access-token"></a><details><summary>(Click to expand) To push additional claims to an Access Token
</summary><br>

```js
{
extraAccessTokenClaims(ctx, token) {
return {
'urn:oidc-provider:example:foo': 'bar',
};
}
}
```
</details>

### extraClientMetadata

Allows for custom client metadata to be defined, validated, manipulated as well as for existing property validations to be extended. Existing properties are snakeCased on a Client instance (e.g. `client.redirectUris`), new properties (defined by this configuration) will be avaialable with their names verbatim (e.g. `client['urn:example:client:my-property']`)
Expand Down Expand Up @@ -2269,6 +2243,32 @@ _**default value**_:
[]
```

### extraTokenClaims

Function used to get additional access token claims when it is being issued. These claims will be available in your storage under property `extra`, returned by introspection as top level claims and pushed into `jwt`, and `jwt-ietf` formatted tokens as top level claims as well. Returned claims may not overwrite other top level claims.



_**default value**_:
```js
async function extraTokenClaims(ctx, token) {
return undefined;
}
```
<a id="extra-token-claims-to-push-additional-claims-to-an-access-token"></a><details><summary>(Click to expand) To push additional claims to an Access Token
</summary><br>

```js
{
extraTokenClaims(ctx, token) {
return {
'urn:oidc-provider:example:foo': 'bar',
};
}
}
```
</details>

### formats

This option allows to configure the token value format. The different values change how a client-facing token value is generated.
Expand Down Expand Up @@ -2318,7 +2318,7 @@ Configure `formats`:

### formats.customizers

Functions used before signing a structured Access Token of a given type, such as a JWT one. Customizing here only changes the structured Access Token, not your storage, introspection or anything else. For such extras use [`extraAccessTokenClaims`](#extraaccesstokenclaims) instead.
Functions used before signing a structured Access Token of a given type, such as a JWT one. Customizing here only changes the structured Access Token, not your storage, introspection or anything else. For such extras use [`extraTokenClaims`](#extratokenclaims) instead.



Expand Down
2 changes: 1 addition & 1 deletion example/my_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MyAdapter {
* - authTime {number} - timestamp of the end-user's authentication
* - claims {object} - claims parameter (see claims in OIDC Core 1.0), rejected claims
* are, in addition, pushed in as an Array of Strings in the `rejected` property.
* - extra {object} - extra claims returned by the extraAccessTokenClaims helper
* - extra {object} - extra claims returned by the extraTokenClaims helper
* - codeChallenge {string} - client provided PKCE code_challenge value
* - codeChallengeMethod {string} - client provided PKCE code_challenge_method value
* - sessionUid {string} - uid of a session this token stems from
Expand Down
10 changes: 5 additions & 5 deletions lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function webMessageResponseModeScriptNonce(ctx) { // eslint-disable-line no-unus
return undefined;
}

async function extraAccessTokenClaims(ctx, token) { // eslint-disable-line no-unused-vars
async function extraTokenClaims(ctx, token) { // eslint-disable-line no-unused-vars
return undefined;
}

Expand Down Expand Up @@ -1635,7 +1635,7 @@ function getDefaults() {
},

/*
* extraAccessTokenClaims
* extraTokenClaims
*
* description: Function used to get additional access token claims
* when it is being issued. These claims will be available in your storage under
Expand All @@ -1646,15 +1646,15 @@ function getDefaults() {
* example: To push additional claims to an Access Token
* ```js
* {
* extraAccessTokenClaims(ctx, token) {
* extraTokenClaims(ctx, token) {
* return {
* 'urn:oidc-provider:example:foo': 'bar',
* };
* }
* }
* ```
*/
extraAccessTokenClaims,
extraTokenClaims,

/*
* formats
Expand Down Expand Up @@ -1709,7 +1709,7 @@ function getDefaults() {
* description: Functions used before signing a structured Access Token of a
* given type, such as a JWT one. Customizing here only changes the structured Access
* Token, not your storage, introspection or anything else. For such extras use
* [`extraAccessTokenClaims`](#extraaccesstokenclaims) instead.
* [`extraTokenClaims`](#extratokenclaims) instead.
*
* example: To push additional claims to a `jwt` format Access Token payload
* ```js
Expand Down
2 changes: 1 addition & 1 deletion lib/models/formats/opaque.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (provider) => ({
};

if (withExtra.has(this.kind)) {
payload.extra = await instance(provider).configuration('extraAccessTokenClaims')(ctxRef.get(this), this);
payload.extra = await instance(provider).configuration('extraTokenClaims')(ctxRef.get(this), this);
}

return [value, payload];
Expand Down
2 changes: 1 addition & 1 deletion test/formats/formats.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const merge = require('lodash/merge');

const config = cloneDeep(require('../default.config'));

config.extraAccessTokenClaims = () => ({ foo: 'bar' });
config.extraTokenClaims = () => ({ foo: 'bar' });
merge(config.features, {
registration: {
initialAccessToken: true,
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ export interface Configuration {
};
};

extraAccessTokenClaims?: (ctx: KoaContextWithOIDC, token: AccessToken | ClientCredentials) => CanBePromise<AnyObject | void | undefined> ;
extraTokenClaims?: (ctx: KoaContextWithOIDC, token: AccessToken | ClientCredentials) => CanBePromise<AnyObject | void | undefined> ;

formats?: {
AccessToken?: AccessTokenFormatFunction | TokenFormat;
Expand Down
2 changes: 1 addition & 1 deletion types/oidc-provider-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const provider = new Provider('https://op.example.com', {
},
},
extraParams: ['foo', 'bar', 'baz'],
async extraAccessTokenClaims(ctx, token) {
async extraTokenClaims(ctx, token) {
ctx.oidc.issuer.substring(0);
token.jti.substring(0);

Expand Down

0 comments on commit ce57d6d

Please sign in to comment.