node.js - 护照 facebook 注销不起作用

标签 node.js facebook passwords

我试图实现护照 Facebook 我在 server.js 中的代码如下所示 当用户通过 facebook 点击登录时使用的路由

 router.get('/auth/facebook',
      passport.authenticate('facebook',{ scope : 'email' }),
      function(req, res){
      });

成功登录后,它会重定向到 success.html 作为注销按钮

 router.get('/auth/facebook/callback',
      passport.authenticate('facebook', {
        successRedirect : '/success',
        failureRedirect: '/'
      }),
      function(req, res) {
        res.render('success.html');
      });

注销路径是

  router.get('/logout', function(req, res){
      req.logout();
      res.redirect('/');
    });

如果我仍然点击注销按钮,我将被重定向到主页

router.get('/', function(req, res){
  res.render('auth.html');
});

auth.html

  <html>
        <head>
          <title>Node.js OAuth</title>
        </head>
        <body>
        <a href="/auth/facebook">Sign in with Facebook</a>
        </body>
        </html>




but after if i click the Sign in with Facebook link i will directly take to success.html page  and again i was never able to see the Facebook login page where we provide the credentials of the Facebook account 

*我尝试从数据库中删除详细信息,但它仍然指向 success.html *我尝试通过删除 cookie 以及浏览器的新实例 *运气不好,请指出我可能犯的错误

最佳答案

您的页面被重定向到“success.html”,因为 Facebook 会记住登录凭据。除非您手动从 Facebook 注销,否则您的应用程序将始终被重定向到“success.html”。

这是从您的应用程序中退出 Facebook 的方法。

在您的 logout.html 页面中:

<form action="/logoutFromFacebook" method="POST">
  <input type="hidden" name="accessToken" value="<%= user.accessToken %>"/>
</form>

以下代码进入您的 Controller :

router.post('/logoutFromFacebook', function(req, res) {
    res.redirect('https://www.facebook.com/logout.php?next='+server.ip+'/logout&access_token='+req.body['accessToken']);
});

router.get('/logout', function(req, res){
  req.logout();
  res.redirect('/');
});

server.ip 需要是您的应用运行的 url。
例如:http://localhost:3000如果它在本地运行
或者
http://128.800.90.67:3000如果它在远程运行

关于node.js - 护照 facebook 注销不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32985655/

相关文章:

node.js - 对于 DynamoDB 和 Node ,我应该使用数据映射器吗?

javascript - 如何在我的代码中实现回调/等待?

node.js - 子 package.json 中的根 package.json 未满足依赖关系

android - Facebook Android 客户端到自定义应用程序通知

node.js - 我应该选择哪个版本的 Node.js

javascript - 如何在用户喜欢带有 Facebook Like 插件的页面后注销用户?

ios - 我需要创建一个Facebook应用程序才能使用Facebook登录吗?

php - Symfony 3.4 - 服务配置不正确

c# - 如何轻松地在 C# Windows 窗体应用程序中添加密码?

php - MySQL删除过期值