-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add hook to handle OAuth Access Token Response #174
base: master
Are you sure you want to change the base?
Add hook to handle OAuth Access Token Response #174
Conversation
request before validation
lib/strategy.js
Outdated
@@ -206,11 +209,14 @@ OAuth2Strategy.prototype.authenticate = function(req, options) { | |||
} | |||
} | |||
} catch (ex) { | |||
console.log(ex); |
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.
rm
@jaredhanson Hello! What are the next steps to get this PR merged? |
My main concern here is that, while Slack claims to be implementing OAuth 2.0, they don't follow the specification at all (thus, its not really OAuth 2.0). While the hook that you've implemented seems reasonable as an extensibility point, I generally favor adding extensibility when its clear that multiple implementations need to be swapped in. In this case, the only "consumer" of this extensibility is Slack, and its only because its not implementing the spec. If it did implement the spec, the hook here wouldn't be needed. One approach I would recommend would be to fork this package, publish it as |
@jaredhanson all good points. And I understand not wanting to create another maintenance burden. In the same vein, I don't have a desire to maintain a Would you be wiling to accept a PR for an extensibility point with an even smaller footprint? The current solution creates a path for IO work to be done, however it is not required. The solution would look something like: OAuth2Strategy.prototype.handleOAuthAccessTokenResponse = function(accessToken, refreshToken, params) {
return { accessToken, refreshToken, params };
}; which is similar to the OAuth2Strategy.prototype.authorizationParams = function(options) {
return {};
}; and OAuth2Strategy.prototype.tokenParams = function(options) {
return {};
}; This hook would manifest in code as self._oauth2.getOAuthAccessToken(code, params, function(err, accessToken, refreshToken, params) {
if (err) { return self.error(self._createOAuthError('Failed to obtain access token', err));
{ accessToken, refreshToken, params } = self.handleOAuthAccessTokenResponse(accessToken, refreshToken, params);
// ...
}); Please let me know, I look forward to your response. Also, in order to unblock my slack integration needs, I've taken the least desirable approach and monkey patched |
Add the method
handleOAuthTokenResponse
to allow subclasses to reformat the OAuth Token response before continuing throw the flow.See: nmaves/passport-slack-oauth2#13
Slack's OAuth2 v2 implementation overrides the token response to return multiple tokens. A scenario may exist where a user will authenticate with "bot scope only" and a user accessToken is not returned. This hook allows the passport-slack-oauth2 provider to reformat the OAuthTokenResponse object such that passport can successfully authenticate for bot only access.