Skip to content

Commit c299425

Browse files
authored
fix: await getUserFromClient in client credentials grant
Merge pull request #218 from shrihari-prakash/release-5.0.0 thanks to @shrihari-prakash
2 parents 6cfb8f0 + 76c1c62 commit c299425

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: lib/grant-types/client-credentials-grant-type.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ClientCredentialsGrantType extends AbstractGrantType {
4545
}
4646

4747
const scope = this.getScope(request);
48-
const user = this.getUserFromClient(client);
48+
const user = await this.getUserFromClient(client);
4949

5050
return this.saveToken(user, client, scope);
5151
}

Diff for: test/integration/grant-types/client-credentials-grant-type_test.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,21 @@ describe('ClientCredentialsGrantType integration', function() {
9393
it('should return a token', function() {
9494
const token = {};
9595
const model = {
96-
getUserFromClient: function() { return {}; },
97-
saveToken: function() { return token; },
96+
getUserFromClient: async function(client) {
97+
client.foo.should.equal('bar');
98+
return { id: '123'};
99+
},
100+
saveToken: async function(_token, client, user) {
101+
client.foo.should.equal('bar');
102+
user.id.should.equal('123');
103+
return token;
104+
},
98105
validateScope: function() { return 'foo'; }
99106
};
100107
const grantType = new ClientCredentialsGrantType({ accessTokenLifetime: 120, model: model });
101108
const request = new Request({ body: {}, headers: {}, method: {}, query: {} });
102109

103-
return grantType.handle(request, {})
110+
return grantType.handle(request, { foo: 'bar' })
104111
.then(function(data) {
105112
data.should.equal(token);
106113
})

0 commit comments

Comments
 (0)