Monkey Patch _oauth2.getOAuthAccessToken to reformat Slack's OAuth2 v2 token response #14
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.
A proposed change to add a hook that would allow this strategy to reformat the OAuth2 Token Response before sending it forward to the
passport-oauth2
callback received some reasonable (though unfortunate) push back.I took the advice in the push back, though probably the wrong part, and chose to not implement a solution that created a "maintenance burden". This new pr monkey patches node-oauth's OAuth2.getOAuthAccessToken method to reformat the OAuth2 Token Response before sending it forward to the
passport-oauth2
callback.This change introduces the method getOAuthAccessTokenAndHandleResponse which wraps
this._oauth2.getOAuthAccessToken
and reformats the response before sending it forward to the callback.Original Summary for PR #13
Please see jaredhanson/passport-oauth2#174 AND #9
Slack's OAuth2 v2 implementation overloads the OAuthTokenResponse json payload to return multiple tokens. The root of the json object is for
bot
tokens & user tokens exist in a property calledauthed_user
.Passport is designed to authenticate Users. When passport attempts to use the root level accessToken, it either does not exist (no bot scopes provided in authorization request) or is a bot token.
This change leverages a new hook in the passport-oauth2 library to reformat the OAuthTokenResponse payload to set the correct
accessToken
,refreshToken
, andparams
for the following scenarios:The profileUrl is no longer defaulted during configuration. When the profile is not being skipped & a custom profileUrl was not provided, the profileUrl is set during
handleOAuthAccessTokenResponse
depending on which token is the root of the params object.if this is merged, the README should be updated to emphasize the verify callback that accepts the params object from the OAuthTokenResponse request.
the params object will be reformatted to:
user_scope
- user onlyscope
- bot onlyscope
&user_scope
- bot & user