Skip to content

fix cannot use this inside model #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/grant-types/abstract-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function AbstractGrantType(options) {

AbstractGrantType.prototype.generateAccessToken = function() {
if (this.model.generateAccessToken) {
return Promise.try(this.model.generateAccessToken);
return Promise.try(this.model.generateAccessToken,[], this.model);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a space before [] please? 😄

}

return tokenUtil.generateRandomToken();
Expand All @@ -48,7 +48,7 @@ AbstractGrantType.prototype.generateAccessToken = function() {

AbstractGrantType.prototype.generateRefreshToken = function() {
if (this.model.generateRefreshToken) {
return Promise.try(this.model.generateRefreshToken);
return Promise.try(this.model.generateRefreshToken,[], this.model);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a space before [] please? 😄

}

return tokenUtil.generateRandomToken();
Expand Down Expand Up @@ -94,7 +94,7 @@ AbstractGrantType.prototype.getScope = function(request) {
* Validate requested scope.
*/
AbstractGrantType.prototype.validateScope = function(user, client, scope) {
return Promise.try(this.model.validateScope, [user, client, scope])
return Promise.try(this.model.validateScope, [user, client, scope], this.model)
.then(function(scope) {
if(!scope) {
throw new InvalidScopeError('Invalid scope: Requested scope is invalid');
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/authorization-code-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl
throw new InvalidRequestError('Invalid parameter: `code`');
}

return Promise.try(this.model.getAuthorizationCode, request.body.code)
return Promise.try(this.model.getAuthorizationCode, request.body.code, this.model)
.then(function(code) {
if (!code) {
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
Expand Down Expand Up @@ -160,7 +160,7 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl
*/

AuthorizationCodeGrantType.prototype.revokeAuthorizationCode = function(code) {
return Promise.try(this.model.revokeAuthorizationCode, code)
return Promise.try(this.model.revokeAuthorizationCode, code, this.model)
.then(function(code) {
if (!code) {
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
Expand Down
2 changes: 1 addition & 1 deletion lib/grant-types/client-credentials-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ClientCredentialsGrantType.prototype.handle = function(request, client) {
*/

ClientCredentialsGrantType.prototype.getUserFromClient = function(client) {
return Promise.try(this.model.getUserFromClient, client)
return Promise.try(this.model.getUserFromClient, client, this.model)
.then(function(user) {
if (!user) {
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
Expand Down
2 changes: 1 addition & 1 deletion lib/grant-types/password-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ PasswordGrantType.prototype.getUser = function(request) {
throw new InvalidRequestError('Invalid parameter: `password`');
}

return Promise.try(this.model.getUser, [request.body.username, request.body.password])
return Promise.try(this.model.getUser, [request.body.username, request.body.password], this.model)
.then(function(user) {
if (!user) {
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/refresh-token-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ RefreshTokenGrantType.prototype.getRefreshToken = function(request, client) {
throw new InvalidRequestError('Invalid parameter: `refresh_token`');
}

return Promise.try(this.model.getRefreshToken, request.body.refresh_token)
return Promise.try(this.model.getRefreshToken, request.body.refresh_token, this.model)
.then(function(token) {
if (!token) {
throw new InvalidGrantError('Invalid grant: refresh token is invalid');
Expand Down Expand Up @@ -122,7 +122,7 @@ RefreshTokenGrantType.prototype.getRefreshToken = function(request, client) {
*/

RefreshTokenGrantType.prototype.revokeToken = function(token) {
return Promise.try(this.model.revokeToken, token)
return Promise.try(this.model.revokeToken, token, this.model)
.then(function(token) {
if (!token) {
throw new InvalidGrantError('Invalid grant: refresh token is invalid');
Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/authenticate-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ AuthenticateHandler.prototype.getTokenFromRequestBody = function(request) {
*/

AuthenticateHandler.prototype.getAccessToken = function(token) {
return Promise.try(this.model.getAccessToken, token)
return Promise.try(this.model.getAccessToken, token, this.model)
.then(function(accessToken) {
if (!accessToken) {
throw new InvalidTokenError('Invalid token: access token is invalid');
Expand Down Expand Up @@ -231,7 +231,7 @@ AuthenticateHandler.prototype.validateAccessToken = function(accessToken) {
*/

AuthenticateHandler.prototype.verifyScope = function(accessToken) {
return Promise.try(this.model.verifyScope, [accessToken, this.scope]).then(function(scope) {
return Promise.try(this.model.verifyScope, [accessToken, this.scope], this.model).then(function(scope) {
if (!scope) {
throw new InvalidScopeError('Invalid scope: scope is invalid');
}
Expand Down
8 changes: 4 additions & 4 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ AuthorizeHandler.prototype.handle = function(request, response) {

AuthorizeHandler.prototype.generateAuthorizationCode = function() {
if (this.model.generateAuthorizationCode) {
return Promise.try(this.model.generateAuthorizationCode);
return Promise.try(this.model.generateAuthorizationCode, [], this.model);
}

return tokenUtil.generateRandomToken();
Expand Down Expand Up @@ -168,7 +168,7 @@ AuthorizeHandler.prototype.getClient = function(request) {
throw new InvalidRequestError('Invalid request: `redirect_uri` is not a valid URI');
}

return Promise.try(this.model.getClient, clientId)
return Promise.try(this.model.getClient, clientId, this.model)
.then(function(client) {
if (!client) {
throw new InvalidClientError('Invalid client: client credentials are invalid');
Expand Down Expand Up @@ -235,7 +235,7 @@ AuthorizeHandler.prototype.getUser = function(request, response) {
return this.authenticateHandler.handle(request, response).get('user');
}

return Promise.try(this.authenticateHandler.handle, [request, response]).then(function(user) {
return Promise.try(this.authenticateHandler.handle, [request, response], this.model).then(function(user) {
if (!user) {
throw new ServerError('Server error: `handle()` did not return a `user` object');
}
Expand Down Expand Up @@ -264,7 +264,7 @@ AuthorizeHandler.prototype.saveAuthorizationCode = function(authorizationCode, e
scope: scope
};

return Promise.try(this.model.saveAuthorizationCode, [code, client, user]);
return Promise.try(this.model.saveAuthorizationCode, [code, client, user], this.model);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/token-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ TokenHandler.prototype.getClient = function(request, response) {
throw new InvalidRequestError('Invalid parameter: `client_secret`');
}

return Promise.try(this.model.getClient, [credentials.clientId, credentials.clientSecret])
return Promise.try(this.model.getClient, [credentials.clientId, credentials.clientSecret], this.model)
.then(function(client) {
if (!client) {
throw new InvalidClientError('Invalid client: client is invalid');
Expand Down