I am building an app for Slack with an attached web interface/team dashboard. Built in node, I'm struggling getting Slack auth and Client auth into one fluid motion.
I'm using passport.js for auth, with Slack Strategy to authenticate users for using the app within Slack (using a Sign in with Slack button). This Slack auth's callback contains all of the user information I'd need, so I want to use this to also authenticate the user to access their team's dashboard in the web client. This is where JWT comes into play.
It's my first time working with JWT auth but theoretically, it makes sense that there would be a way to use passport's JWT strategy to authenticate for the client.
Here is the code for the passport Slack strategy that works fine:
passport.use(
new SlackStrategy(
{
clientID: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
scope: [
'identity.basic',
'identity.avatar',
'identity.email',
'identity.team',
'users.list',
'chat:write:bot',
],
skipUserProfile: false,
},
(accessToken, scopes, team, extra, profiles, done) => {
if (extra.bot != null) {
Team.postTeamOnInstall(team, extra.bot.accessToken)
} else {
User.postUser(accessToken, profiles)
}
done(null, {})
}
)
)
app.get(
'/auth/slack',
passport.authenticate('slack', {
scope: ['bot'],
})
)
app.get(
'/auth/slack/callback',
passport.authenticate('slack', { session: false }),
(req, res) => {
// what if called JWT authentication here? that then redirects to the team dashboard
res.redirect(`http://${process.env.BASE_URL}`)
},
(err, erq, res, next) => {
res
.status(500)
.send(`<p>Think Fish failed to install</p> <pre>${err}</pre>`)
}
)
Now I've followed a basic tutorial for the JWT strategy. So my code on that side of things looks identical to that. I really just want to know:
1) Has anybody done this or something similar? Am I thinking about this the right way? Is this possible?
2) If so, how do Slack Strategy and the JWT Strategy be talk to each other to get a user authenticated for Slack and client in one fluid motion (Sign in with Slack button)?
I could also be over-engineering this, and instead just need some sort of way for a secure route to check if the user is logged into Slack already?