Created
May 11, 2020 02:00
-
-
Save drewrothstein/d0de715ea003427dff933fcec0fa69c4 to your computer and use it in GitHub Desktop.
Slack OAuth v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const installUrl = `https://slack.com/oauth/v2/authorize?\ | |
client_id=${process.env.SLACK_CLIENT_ID}&scope=${process.env.SLACK_SCOPES}`; | |
module.exports.save = async function (data) { | |
await saveDoc(data); | |
} | |
var saveDoc = async function(data) { | |
// | |
} | |
module.exports.install = (app, slack) => { | |
app.route('/oauth') | |
.get((request, response) => { | |
console.log('Request for /oauth'); | |
const payload = request.query; | |
if (!payload.code) { | |
return response.redirect(302, installUrl); | |
} | |
return slack.oauth.v2 | |
.access({ | |
client_id: process.env.SLACK_CLIENT_ID, | |
client_secret: process.env.SLACK_CLIENT_SECRET, | |
code: payload.code, | |
state: payload.state | |
}) | |
.then(data => { | |
console.log('Saving auth data for:', data.team.id); | |
const save = this.save({ | |
// | |
}); | |
const test = slack.auth.test({ token: data.access_token }); | |
Promise.all([test]).then(results => { | |
response.redirect(302, results[0].url); | |
}); | |
}) | |
.catch(error => { | |
console.log('Error with /oauth:', error) | |
response.status(500).send(error); | |
}) | |
}); | |
app.route('/install') | |
.get((request, response) => { | |
console.log('Request for /install'); | |
response.redirect(302, installUrl); | |
}) | |
} | |
module.exports.auth = ({ teamId }) => { | |
console.log('Request for .auth for:', teamId); | |
// | |
return Promise.resolve(getDoc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment