Last active
October 27, 2018 16:52
-
-
Save anabellaspinelli/f14dcc1a62ab3411792bd53834fabc1c to your computer and use it in GitHub Desktop.
Basic OAuth client with PassportJS
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 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