-
-
Save tonypee/e54a5581a883378c3b9ef65c698f46b8 to your computer and use it in GitHub Desktop.
passport auth bearer
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
var express = require('express'); | |
var app = express(); | |
var passport = require('passport') | |
, BearerStrategy = require('passport-http-bearer').Strategy; | |
app.use(passport.initialize()); | |
passport.serializeUser(function(user, done) { | |
done(null, user); | |
}); | |
passport.deserializeUser(function(id, done) { | |
done(null, id); | |
}); | |
passport.use(new BearerStrategy( | |
function(token, done) { | |
console.log('check'); | |
done(null, 'you' + token) | |
} | |
)); | |
app.post('/login', | |
function(req, res) { | |
console.log('OGIN FDFD'); | |
} | |
); | |
app.get('/test', | |
passport.authenticate('bearer'), | |
function(req, res) { | |
console.log('OGIN FDFD'); | |
res.send('OK!' + req.user) | |
} | |
); | |
app.listen(3000) | |
console.log('STARTING SERVER...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment