Howto use it with Client / Server style ?
Closed this issue · 2 comments
In Frontend i use a Backbone-MVC Application, this app call github authorize url and recieve the Answer (github code).
Then the Frontend-App post the Code to the Server-App, which should use passport-github to verify and load the data.
The backend use MVC-Style too, not directly call the passport functions in express-routes, example:
UserController.prototype.loginByGitHub = function(req, res)
{
passport.authenticate("github", function(err, user, info) {
console.log(err);
console.log(user);
console.log(info);
// if ok login / register user
// ....
})(req, res);
};
One problem is in passport-oauth/strategies/oauth2.js
if (req.query && req.query.code) {
is always empty, because i post the data.
But if i change the line to
if (req.body && req.body.code) {
i got TypeError: Property 'next' of object # is not a function, line 128
Is there an ohter way to use the verification on the server-side with passport-github?
I use Nginx to pass the '/auth' & '/auth/callback' url to the backend, this way you don't have this problem.
Also to fix the second error, you need to pass an function as third parameter to execute, like so:
passport.authenticate('github', function () {
// ...
})(req, res, function (req, res) {
res.redirect('/');
});
then the final function will get called, because it's just express middleware.
Thank you! I overlook the obvious, that it is an express middleware ;-)