Skip to content

Instantly share code, notes, and snippets.

@bytespider
Last active December 24, 2015 09:39
Show Gist options
  • Save bytespider/6778978 to your computer and use it in GitHub Desktop.
Save bytespider/6778978 to your computer and use it in GitHub Desktop.
Authenticating Geddy.js with Passport HTTP Bearer
var passport = require('passport');
var BearerStrategy = require('passport-http-bearer').Strategy;
var Posts = function () {
var strategy = new BearerStrategy({ session: false }, function ( token, done ) {
if (token == '1234567890') {
return done(null, {username: "someuser"});
}
return done(null);
});
passport.use(strategy);
this.before(function (cb) {
var self = this;
passport.authenticate('bearer', function (err, profile, challenges, statuses) {
if (profile) {
cb();
}
self.output(401, {'WWW-Authenticate': challenges}, '{status: "You\'re not allowed. Please Authenticate"}');
})(this.request, this.response, function (err) {
if (err) {
self.error(err);
}
});
}, { async: true });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment