From e296dc78247bf9259f088a9b5400cf9d921b23cf Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 30 Aug 2023 12:19:54 +0200 Subject: [PATCH] fix: assign extraTokenClaims return to the model --- lib/models/formats/opaque.js | 3 ++- test/formats/opaque.test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/models/formats/opaque.js b/lib/models/formats/opaque.js index 02dfc0f4b..05cd9f0f7 100644 --- a/lib/models/formats/opaque.js +++ b/lib/models/formats/opaque.js @@ -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 }; diff --git a/test/formats/opaque.test.js b/test/formats/opaque.test.js index 253c153c3..5d32e0972 100644 --- a/test/formats/opaque.test.js +++ b/test/formats/opaque.test.js @@ -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'); @@ -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');