Skip to content
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

SlackJsonTokenExtractor handle null access_token #1037

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peterp-canva
Copy link

@peterp-canva peterp-canva commented Apr 28, 2022

Issue: #1023
Slack does not always provide the bot access token, if you don't ask for those scopes.
Example:

  • Requesting: slack oauth &scope=&user_scope=users.profile%3Aread
  • Response
{"ok":true,"app_id":"AA","authed_user":{"id":"UID","scope":"channels:read,groups:read,users.profile:read,files:write:user","access_token":"xoxp-1234-etc","token_type":"user"},"team":{"id":"TId","name":"TeamName"},"enterprise":{"id":"EId","name":"EName"},"is_enterprise_install":false}

Error - This leads to:

com.github.scribejava.core.exceptions.OAuthException: Response body is incorrect. Can't extract a 'access_token' from this: '{"ok":true,"app_id":"AA",... <as above>'

Solution:

Downgrade "access_token" to not be extractRequiredParameter, by overriding the implementation.

return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse).asText(),

Issue: scribejava#1023
Slack does not always provide the bot access token, if you don't ask for those scopes.
This 

Note - the underlying OAuth2AccessToken has a Precondition for "access_token can't be null", so here it is provided with an empty string.
final JsonNode globalAccessToken = response.get(OAuthConstants.ACCESS_TOKEN);

return createToken( //
globalAccessToken == null ? "" : globalAccessToken.asText(), // Avoid "access_token can't be null"
Copy link
Author

Choose a reason for hiding this comment

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

Note - the underlying OAuth2AccessToken (for SlackOAuth2AccessToken->super()) has a Precondition for "access_token can't be null", so here it is provided with an empty string.
The tokenType will be null, so it is easy to deduce whether the string is meaningful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant