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

Update Slack provider to use V2 OAuth endpoints #895

Merged
merged 5 commits into from
Dec 6, 2020
Merged
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
8 changes: 5 additions & 3 deletions src/providers/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export default (options) => {
name: 'Slack',
type: 'oauth',
version: '2.0',
scope: 'identity.basic identity.email identity.avatar',
scope: [],
params: { grant_type: 'authorization_code' },
accessTokenUrl: 'https://slack.com/api/oauth.access',
authorizationUrl: 'https://slack.com/oauth/authorize?response_type=code',
accessTokenUrl: 'https://slack.com/api/oauth.v2.access',
accessTokenGetter: (json) => json.authed_user.access_token,
authorizationUrl: 'https://slack.com/oauth/v2/authorize',
additionalAuthorizeParams: { user_scope: 'identity.basic,identity.email,identity.avatar' },
profileUrl: 'https://slack.com/api/users.identity',
profile: (profile) => {
const { user } = profile
Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/oauth/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async function _getOAuthAccessToken (code, provider, callback) {
// Clients of these services suffer a minor performance cost.
results = querystring.parse(data)
}
const accessToken = results.access_token
const accessToken = provider.accessTokenGetter ? provider.accessTokenGetter(results) : results.access_token
const refreshToken = results.refresh_token
callback(null, accessToken, refreshToken, results)
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/lib/signin/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default (provider, csrfToken, callback, authParams) => {
redirect_uri: provider.callbackUrl,
scope: provider.scope,
// A hash of the NextAuth.js CSRF token is used as the state
state: createHash('sha256').update(csrfToken).digest('hex')
state: createHash('sha256').update(csrfToken).digest('hex'),
...provider.additionalAuthorizeParams
})

// If the authorizationUrl specified in the config has query parameters on it
Expand Down
1 change: 1 addition & 0 deletions www/docs/configuration/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ providers: [
| scope | OAuth access scopes (expects array or string) | No |
| params | Additional authorization URL parameters | No |
| accessTokenUrl | Endpoint to retrieve an access token | Yes |
| accessTokenGetter | Default `(json) => json.access_token` | No |
| requestTokenUrl | Endpoint to retrieve a request token | No |
| authorizationUrl | Endpoint to request authorization from the user | Yes |
| profileUrl | Endpoint to retrieve the user's profile | No |
Expand Down