Skip to content

Commit

Permalink
update(provider): Update Slack provider to use V2 OAuth endpoints (#895)
Browse files Browse the repository at this point in the history
* Update Slack to v2 authorize urls, option for additional authorize params
* acessTokenGetter + documentation
  • Loading branch information
cathykc committed Dec 6, 2020
1 parent dde908b commit 9dbd372
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/providers/slack.js
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
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
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
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

0 comments on commit 9dbd372

Please sign in to comment.