Skip to content

Instantly share code, notes, and snippets.

@tonypee
Created May 19, 2017 08:09
Show Gist options
  • Save tonypee/e54a5581a883378c3b9ef65c698f46b8 to your computer and use it in GitHub Desktop.
Save tonypee/e54a5581a883378c3b9ef65c698f46b8 to your computer and use it in GitHub Desktop.
passport auth bearer
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