passport google oauth on localhost

前端 未结 3 931
时光取名叫无心
时光取名叫无心 2020-12-30 04:49

I am quite new at using passport for authentication over node, hence the lot of code snippets

my server is configured as :

var router = require(\'./a         


        
3条回答
  •  梦毁少年i
    2020-12-30 05:22

    In most examples on the web, routing code is done like this:

    app.get('/auth/google', passport.authenticate('google'));
    

    According to the Express Reference, callbacks of the app.get method are given three arguments, request, response and 'next'. That means, the authenticate method in the above example returns a function object and it is executed with three the arguments request, response and 'next'.

    So, if you would like do authentication in the callback function of the app.get method like this:

    app.get('/auth/google', function() {
        passport.authenticate('google', {scope: ['profile', 'email']});
    });
    

    then you should write:

    app.get('/auth/google', function(request, response, next) {
        passport.authenticate('google', {scope: ['profile', 'email']})(request, response, next);
    });
    

提交回复
热议问题