Can the callback for facebook-pasport be dynamically constructed?

前端 未结 3 1341
轮回少年
轮回少年 2020-12-25 07:48

When using facebook-passport the usual thing to do is to specify the redirect_uri in the constructor of the FacebookStrategy thst you use, something like this:<

3条回答
  •  既然无缘
    2020-12-25 08:49

    I was struggling to do this specifically with Angularjs, and wanted to redirect back to the same url that the login was initiated from.

    My solution was to create a route in Angularjs that just implements a location back. I know this does not specifically answer the question, but I thought it would be helpful for anyone looking to do the same.

    On the server:

    app.get('/auth/facebook/', passport.authenticate ('facebook'));
    
    app.get('/auth/facebook/callback', function (req, res, next) {
        var authenticator = passport.authenticate ('facebook', {
                successRedirect: '/fbcallback',
                failureRedirect: '/'
        });
    
        delete req.session.returnTo;
        authenticator (req, res, next);
    })
    

    Angular router:

    when('/fbcallback', {
        template: "",
        controller: 'fbCtrl' 
    }).
    

    Angular controller:

    app.controller("fbCtrl", function () {
        window.history.back();
    });
    

    You could probably do some other client side routing in the controller as well.

提交回复
热议问题