Open
Description
I'm using latest version from master
I found that when using my custom model generateAccessToken
doesn't receive the arguments (client, user, scope)
when using async generateAcessToken
.
I found a solution by binding this
context to each function when declaring the array fns.
In lib/grant-type/grant-type-password.js
PasswordGrantType.prototype.saveToken = function(user, client, scope) {
var fns = [
this.validateScope(user, client, scope),
this.generateAccessToken(client, user, scope).bind(this), // <- adding bind here
this.generateRefreshToken(client, user, scope),
this.getAccessTokenExpiresAt(),
this.getRefreshTokenExpiresAt()
];
return Promise.all(fns)
.bind(this)
.spread(function(scope, accessToken, refreshToken, accessTokenExpiresAt, refreshTokenExpiresAt) {
var token = {
accessToken: accessToken,
accessTokenExpiresAt: accessTokenExpiresAt,
refreshToken: refreshToken,
refreshTokenExpiresAt: refreshTokenExpiresAt,
scope: scope
};
return promisify(this.model.saveToken, 3)(token, client, user);
});
};
If this solution is acceptable I can prepare a pull request.
I guess the same problem will apply to validateScope
and generateRefreshToken
,
and other grant-types
Thanks