Last active
December 24, 2015 09:39
-
-
Save bytespider/6778978 to your computer and use it in GitHub Desktop.
Authenticating Geddy.js with Passport HTTP 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 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