护照 facebook 注销无效的问题

3

我正在尝试实现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并使用新的浏览器实例 *没有成功,请指出可能的错误

3个回答

1
您的页面将被重定向到“success.html”,因为Facebook记住了登录凭据。除非您手动从Facebook注销,否则您的应用程序将始终被重定向到“success.html”。
以下是从您的应用程序中注销Facebook的方法。
在您的logout.html页面中:
<form action="/logoutFromFacebook" method="POST">
  <input type="hidden" name="accessToken" value="<%= user.accessToken %>"/>
</form>

以下代码会放入您的控制器中:

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


0

请查看passport-facebook的重新认证文档

将第一部分更改为类似以下内容:

router.get('/auth/facebook',
  passport.authenticate('facebook', {
    scope: 'email',
    authType: 'reauthenticate',
    authNonce: 'foo123'
  })
);

0
删除与用户关联的 Facebook 令牌。
const url = "https://graph.facebook.com/v15.0/me/permissions?access_token="+accesstoken;
     firstValueFrom(
      this.httpService.delete(url).pipe(
        catchError((error: AxiosError) => {
          throw new InternalServerErrorException(error.response);
        }),
      ),
    );

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接