I have an service and my goal is to let a user auth us to his / her Github account via OAuth. The API layer is stateless, so I don't want to maintain any session information. The code I have so far is:
app.use passport.initialize()
app.use passport.session()
passport.use new GitHubStrategy
clientID: global.config.oauth.github.clientID
clientSecret: global.config.oauth.github.clientSecret
callbackURL: "http://localhost:9500/auth/github/callback"
passReqToCallback: true
, (req, accessToken, refreshToken, profile, done) ->
console.log req.params
serviceQuery =
service: 'github'
provider_id: "#{profile.id}"
UserId: 13
global.db.Service.find
where: serviceQuery
.then (dbService) ->
if not dbService
newService =
service: 'github'
token: accessToken
secret: null
provider_id: profile.id
raw: profile._json
UserId: 13
global.db.Service.create newService
else
dbService.token = accessToken
dbService.raw = profile._json
dbService.save()
.then ->
done null, true
app.get '/auth/github/:sessionToken', (req, res, next) ->
console.log req.params
next()
, passport.authenticate 'github',
scope: 'repo'
session: false
app.get '/auth/github/callback', passport.authenticate('github',
scope: 'repo'
session: false
), (req, res) ->
res.redirect 'http://localhost:8080/app'
So that when the user is directed to /auth/github/:sessionToken
, I want passport
to do its magic and redirect the user to github. This works great. But when they return to /auth/github/callback
, I need to still be able to identify which user it is.
Since this is the API service, it is supposed to be stateless, so as I mentioned before, I'm looking for some way to pass that token to the /auth/github/callback
. How can I accomplish this?
Try a console log of req.user in your /auth/github/callback. I believe the req.user will still be storing their user information. As it appears in this tutorial they pass the user information to be displayed by passing in the req.user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With