From f6db51a36c82b5ce808e8c779bbb54720e43ec4b Mon Sep 17 00:00:00 2001 From: Shrihari Prakash Date: Tue, 15 Aug 2023 13:53:13 +0530 Subject: [PATCH 1/2] Fixed getUserFromClient not awaited. --- lib/grant-types/client-credentials-grant-type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grant-types/client-credentials-grant-type.js b/lib/grant-types/client-credentials-grant-type.js index e2db3f7c..211628d3 100644 --- a/lib/grant-types/client-credentials-grant-type.js +++ b/lib/grant-types/client-credentials-grant-type.js @@ -45,7 +45,7 @@ class ClientCredentialsGrantType extends AbstractGrantType { } const scope = this.getScope(request); - const user = this.getUserFromClient(client); + const user = await this.getUserFromClient(client); return this.saveToken(user, client, scope); } From bfc4e8fa16c777f9ca142437f3890bb786a5a03f Mon Sep 17 00:00:00 2001 From: Shrihari Prakash Date: Tue, 15 Aug 2023 17:05:24 +0530 Subject: [PATCH 2/2] Added tests. --- .../client-credentials-grant-type_test.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/integration/grant-types/client-credentials-grant-type_test.js b/test/integration/grant-types/client-credentials-grant-type_test.js index 83de9f9a..1a70874e 100644 --- a/test/integration/grant-types/client-credentials-grant-type_test.js +++ b/test/integration/grant-types/client-credentials-grant-type_test.js @@ -93,14 +93,21 @@ describe('ClientCredentialsGrantType integration', function() { it('should return a token', function() { const token = {}; const model = { - getUserFromClient: function() { return {}; }, - saveToken: function() { return token; }, + getUserFromClient: async function(client) { + client.foo.should.equal('bar'); + return { id: '123'}; + }, + saveToken: async function(_token, client, user) { + client.foo.should.equal('bar'); + user.id.should.equal('123'); + return token; + }, validateScope: function() { return 'foo'; } }; const grantType = new ClientCredentialsGrantType({ accessTokenLifetime: 120, model: model }); const request = new Request({ body: {}, headers: {}, method: {}, query: {} }); - return grantType.handle(request, {}) + return grantType.handle(request, { foo: 'bar' }) .then(function(data) { data.should.equal(token); })