Passport Facebook身份验证不起作用 [英] Passport facebook authentication not working

查看:316
本文介绍了Passport Facebook身份验证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个nodeJS应用程序(快速),它具有一个Facebook登录名.我使用的是护照-facebook"身份验证,如此处 passport-facebook 所述.几周前我的登录仍然可以正常工作,但是现在情况有所改变.我不确定Facebook是否已更改某些内容,或者我是否已更改.我没有涉及任何登录代码,因此我怀疑这是在Facebook的末尾.

I have a nodeJS application (express), which has a facebook login. I'm using the passport-facebook authentication, described in here passport-facebook. My login was still working couple weeks ago ok, but now something has changed. I'm not sure if Facebook has changed something, or if I have. I haven't touched to any of the login code, so I suspect it is something in the facebook's end.

这是我的验证码:

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

router.get('/auth/facebook/callback', passport.authenticate('facebook', {
  failureRedirect: '/' }),
  function(req, res) {
  res.redirect('/calendar');
});

基本上,我希望应用程序从应用程序的根目录自动对用户进行身份验证,然后在身份验证后重定向到/calendar.

Basically, I want the app to automatically authenticate the user from the root of the app, and then redirect after the authentication to /calendar.

以下是症状:如果我尝试进入根目录并且之前没有使用Facebook登录,那么它将带我进入正常的Facebook登录屏幕.但随后在该屏幕上,警告:

The symptons are following: If I try to go to the root and I haven't logged in with facebook earlier, then it will take me to the normal facebook login screen, as it should. But then on that screen, there is a warning of:

应用程序配置不允许提供URL 应用程序的设置不允许使用一个或多个给定的URL.它必须与网站URL或Canvas URL匹配,或者域必须是该应用程序域之一的子域.

Given URL is not permitted by the Application configuration One or more of the given URLs is not permitted by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

我检查了与此相关的所有问题,这似乎是因为我没有在facebook应用程序配置中正确配置应用程序域和站点URL.但它们应该都很好:应用程序域:localhost,站点URL: http://localhost:3000/

I checked all questions related to this, and it seems it is because I haven't configured the app domain and site url properly in the facebook app configuration. But they should be all fine: app domain: localhost, site url: http://localhost:3000/

所以我不知道为什么它抱怨它?我没有任何子域.我唯一拥有的路由是:(/,/calendar,/calendar/events).最后的/calendar/events路由是ajax路由.无论如何,在我输入我的Facebook凭据并登录后,该页面会将我重定向到一个空页面,并带有url:( https://www.facebook.com/login.php?login_attempt=1 ).我打开开发人员的工具,并在其控制台中看到一条错误消息:

So I don't know why it is complaining about it? I do not have any subdomains. The only routes I do have are: (/, /calendar, /calendar/events). The last /calendar/events routes are ajax routes. Anyways, after I enter my facebook credentials and login, then the page will redirect me to a empty page, with url: (https://www.facebook.com/login.php?login_attempt=1). I opened the developer's tools, and I see one error message in its console:

无法加载资源:服务器的状态为500(内部服务器错误)

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

但是,现在我实际上已经登录.因为如果现在进入root或/calendar,它将需要我纠正页面并显示我已正确登录.因此,显然登录可以工作,但是重定向和允许的URL存在一些问题.我只是似乎不知道是什么,为什么.我正在使用mongodDB作为数据库.

But, now I am actually logged in. Because if I now go to root or to /calendar, it will take me to correct page and show I'm logged in properly. So apparently the log in works, but there are some issues with redirection and allowed URL's. I just don't seem to know what and why. I'm using mongodDB as database.

推荐答案

可能是因为您在应用中注册了哪个网站.如果您已将其注册到 http://localhost:3000/,则应使用用于回调的域localhost.如果您将其注册为 http://127.0.0.1:3000/,则应该使用127. ..

It could be because of what site you have registered in your app. If you have registered it to http://localhost:3000/ you should work with domain localhost that for the callback. And if you have registered it as http://127.0.0.1:3000/ then you should work with 127...

这篇关于Passport Facebook身份验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆