Can the callback for facebook-pasport be dynamically constructed?

前端 未结 3 1345
轮回少年
轮回少年 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:37

    I found the answer using some info found here https://github.com/jaredhanson/passport-facebook/issues/2 and through digging through the way the passport oauth2 component determines callback uris, and information about passport custom callbacks at the bottom of this page http://passportjs.org/guide/authenticate/.

    Here's an example that maps calls to /auth/facebook/login/1234 to use the callback /auth/facebook/login_callback/1234

    app.get('/auth/facebook/login/:id', function(req,res,next) {
      passport.authenticate(
        'facebook', 
         {callbackURL: '/auth/facebook/login_callback/'+req.params.id }
      )(req,res,next);
    });
    
    app.get('/auth/facebook/login_callback/:id', function(req,res,next) {
      passport.authenticate(
        'facebook',
         {
           callbackURL:"/auth/facebook/login_callback/"+req.params.id
         , successRedirect:"/login_ok.html"
         , failureRedirect:"/login_failed.html"
         }
       ) (req,res,next);
     });
    

提交回复
热议问题