-
-
Couldn't load subscription status.
- Fork 927
Conditionally promisify all model functions #272
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
Merged
mjsalinger
merged 5 commits into
oauthjs:master
from
mjsalinger:conditionally-promisify
Oct 24, 2016
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ var InvalidArgumentError = require('../errors/invalid-argument-error'); | |
| var InvalidGrantError = require('../errors/invalid-grant-error'); | ||
| var InvalidRequestError = require('../errors/invalid-request-error'); | ||
| var Promise = require('bluebird'); | ||
| var promisify = require('promisify-any').use(Promise); | ||
| var ServerError = require('../errors/server-error'); | ||
| var is = require('../validator/is'); | ||
| var util = require('util'); | ||
|
|
@@ -85,7 +86,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 promisify(this.model.getRefreshToken, 1)(request.body.refresh_token) | ||
| .then(function(token) { | ||
| if (!token) { | ||
| throw new InvalidGrantError('Invalid grant: refresh token is invalid'); | ||
|
|
@@ -122,7 +123,7 @@ RefreshTokenGrantType.prototype.getRefreshToken = function(request, client) { | |
| */ | ||
|
|
||
| RefreshTokenGrantType.prototype.revokeToken = function(token) { | ||
| return Promise.try(this.model.revokeToken, token) | ||
| return promisify(this.model.revokeToken, 1)(token) | ||
| .then(function(status) { | ||
| if (!status) { | ||
| throw new InvalidGrantError('Invalid grant: refresh token is invalid'); | ||
|
|
@@ -155,7 +156,13 @@ RefreshTokenGrantType.prototype.saveToken = function(user, client, scope) { | |
| scope: scope | ||
| }; | ||
|
|
||
| return this.model.saveToken(token, client, user); | ||
| return token; | ||
| }) | ||
| .then(function(token) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding additional |
||
| return Promise.try(promisify(this.model.saveToken, 3), [token, client, user]) | ||
| .then(function(savedToken) { | ||
| return savedToken; | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously
model#validateScopewas a required model function. (Promise.trythrows aTypeErrorif the first argument isn't a function. ) This change makesvalidateScopeoptional.If this is the desired effect there should probably be an
elseaccepting any scope. Something like this should work:Without this addition all scopes are lost, resulting in a call to
model#saveTokenwithtoken.scope === undefined(see for example ClientCredentialsGrantType#saveToken).