Skip to content

Instantly share code, notes, and snippets.

@anabellaspinelli
Last active October 27, 2018 16:52
Show Gist options
  • Save anabellaspinelli/f14dcc1a62ab3411792bd53834fabc1c to your computer and use it in GitHub Desktop.
Save anabellaspinelli/f14dcc1a62ab3411792bd53834fabc1c to your computer and use it in GitHub Desktop.
Basic OAuth client with PassportJS
const passport = require('passport')
const GitHubStrategy = require('passport-github')
passport.use(
new GitHubStrategy(
{
clientID: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackURL: process.env.GITHUB_REDIRECT_URL || '/auth/github/redirect',
scope: ['user:email']
},
(accessToken, refreshToken, profile, done) => {
// This function is the "verify callback".
done(null, { accessToken, profile })
}
)
)
app.get('/auth/github', passport.authenticate('github'))
app.get('/auth/github/redirect',
passport.authenticate('github')
},
(req, res) => {
res.send(req.user)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment