Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created February 22, 2019 15:12
Show Gist options
  • Save brianleroux/8bb4463234c220989bc58764b4bb47b0 to your computer and use it in GitHub Desktop.
Save brianleroux/8bb4463234c220989bc58764b4bb47b0 to your computer and use it in GitHub Desktop.
how to sign in with slack
let tiny = require('tiny-json-http')
module.exports = async function slack(code) {
// trade the code for an access token
let result = await tiny.get({
url: `https://slack.com/api/oauth.access`,
data: {
client_id: process.env.SLACK_CLIENT_ID,
client_secret: process.env.SLACK_CLIENT_SECRET,
code,
}
})
let token = result.body.access_token
// get the user account
let account = await tiny.get({
url: 'https://slack.com/api/users.identity',
data: {token}
})
return {token, ...account.body.user}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment