Skip to content

Commit

Permalink
fix: assign extraTokenClaims return to the model
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 30, 2023
1 parent 2870fe0 commit e296dc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/models/formats/opaque.js
Expand Up @@ -35,7 +35,8 @@ export default (provider) => ({
};

if (withExtra.has(this.kind)) {
payload.extra = await instance(provider).configuration('extraTokenClaims')(ctxRef.get(this), this);
// eslint-disable-next-line no-multi-assign
payload.extra = this.extra = await instance(provider).configuration('extraTokenClaims')(ctxRef.get(this), this);
}

return { value: this.jti, payload };
Expand Down
16 changes: 16 additions & 0 deletions test/formats/opaque.test.js
Expand Up @@ -84,6 +84,14 @@ describe('opaque storage', () => {
});
});

it('for AccessToken extraTokenClaims gets assigned upon save()', async function () {
const client = await this.provider.Client.find(clientId);
const token = new this.provider.AccessToken({ client, ...fullPayload, extra: undefined });
expect(token.extra).to.eql(undefined);
await token.save();
expect(token.extra).to.eql(extra);
});

it('for AuthorizationCode', async function () {
const kind = 'AuthorizationCode';
const upsert = spy(this.TestAdapter.for('AuthorizationCode'), 'upsert');
Expand Down Expand Up @@ -244,6 +252,14 @@ describe('opaque storage', () => {
});
});

it('for ClientCredentials extraTokenClaims gets assigned upon save()', async function () {
const client = await this.provider.Client.find(clientId);
const token = new this.provider.ClientCredentials({ client, ...fullPayload, extra: undefined });
expect(token.extra).to.eql(undefined);
await token.save();
expect(token.extra).to.eql(extra);
});

it('for InitialAccessToken', async function () {
const kind = 'InitialAccessToken';
const upsert = spy(this.TestAdapter.for('InitialAccessToken'), 'upsert');
Expand Down

0 comments on commit e296dc7

Please sign in to comment.