代码之家  ›  专栏  ›  技术社区  ›  shamon shamsudeen

passport Js:重定向到另一个包含数据的url

  •  1
  • shamon shamsudeen  · 技术社区  · 7 年前

    从passportjs文档中,我可以重定向到一个URL

    app.post('/login',
      passport.authenticate('local', { successRedirect: '/',
                                       failureRedirect: '/login' }));
    

    successRedirect 应该是另一个不同的领域假设 www.auth.com 成功登录后,我想重定向到 www.customer.com/callback www.auth.com网站

    这实际上就像是成功登录Facebook后使用回调URL进行的Facebook身份验证 POST 回调URL的数据

    1 回复  |  直到 7 年前
        1
  •  0
  •   Parth Raval    7 年前
    app.get('/login', function(req, res) { //will handle if user fails to enter valid credentials
      return res.render('login', {
        message: 'Login Page Renderd...'
      });
    });
    
    app.post('/login', passport.authenticate('local', {
      successRedirect: '/profile', //will be redirected to `/profile` route after successful login
      failureRedirect: '/login' //will be redirected to `/login` route for failure
    }));
    
    app.get('/profile', function(req, res) { //will handle if user enter valid credentials means user logged in successfully
      return res.status(200).send('User Logged in successfully...');
    });
    

    Passport-Facebook 我们需要为身份验证的成功和失败定义回调url,与 Passport-Local

    推荐文章