简体   繁体   English

Passport Facebook身份验证不起作用

[英]Passport facebook authentication not working

I have a nodeJS application (express), which has a facebook login. 我有一个nodeJS应用程序(快速),具有Facebook登录名。 I'm using the passport-facebook authentication, described in here passport-facebook . 我使用的是password-facebook身份验证,如此处password-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. 我不确定Facebook是否已更改某些内容,或者是否已更改。 I haven't touched to any of the login code, so I suspect it is something in the facebook's end. 我没有涉及任何登录代码,因此我怀疑这是在Facebook的末尾。

Here is my authentication code: 这是我的验证码:

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

router.get('/auth/facebook/callback', passport.authenticate('facebook', {
  failureRedirect: '/' }),
  function(req, res) {
  res.redirect('/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. 基本上,我希望应用程序从应用程序的根目录自动对用户进行身份验证,然后在身份验证后重定向到/ calendar。

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. 出现的症状如下:如果我尝试进入根目录并且之前没有使用Facebook登录,那么它将带我进入正常的Facebook登录屏幕。 But then on that screen, there is a warning of: 但随后在该屏幕上,出现以下警告:

Given URL is not permitted by the Application configuration One or more of the given URLs is not permitted by the App's settings. 应用程序配置不允许使用给定的URL应用程序的设置不允许使用一个或多个给定的URL。 It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains. 它必须与网站URL或Canvas URL匹配,或者域必须是该应用程序域之一的子域。

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. 我检查了与此相关的所有问题,这似乎是因为我没有在facebook应用程序配置中正确配置应用程序域和网站url。 But they should be all fine: app domain: localhost, site url: http://localhost:3000/ 但它们应该都很好:应用程序域:localhost,站点URL: http:// localhost:3000 /

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). 我唯一拥有的路由是:(/,/ calendar,/ calendar / events)。 The last /calendar/events routes are ajax routes. 最后的/ calendar / events路由是ajax路由。 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 ). 无论如何,输入我的Facebook凭据并登录后,该页面会将我重定向到一个空页面,并带有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: 我打开开发人员的工具,并在其控制台中看到一条错误消息:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) 加载资源失败:服务器响应状态为500(内部服务器错误)

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. 但是,现在我实际上已经登录。因为如果现在进入root或/ calendar,它将需要我纠正页面并显示我已正确登录。 So apparently the log in works, but there are some issues with redirection and allowed URL's. 因此,显然登录可以工作,但是重定向和允许的URL存在一些问题。 I just don't seem to know what and why. 我只是似乎不知道什么,为什么。 I'm using mongodDB as database. 我正在使用mongodDB作为数据库。

I have no idea why this even worked, but I found a solution. 我不知道为什么这仍然有效,但是我找到了解决方案。 Previously, I had configured valid OAuth redirect URI to be http://127.0.0.1:3000/auth/facebook/callback , and it was working all good. 以前,我已经将有效的OAuth重定向URI配置为http://127.0.0.1:3000/auth/facebook/callback ,并且运行良好。 Now I changed it to use localhost instead of 127.0.0.1:3000, and that seemed to do the trick. 现在,我将其更改为使用localhost而不是127.0.0.1:3000,这似乎可以解决问题。 Now everything is working as expected, though I don't know why. 现在一切都按预期工作,尽管我不知道为什么。 If someone is able to clearly tell me why, I will mark that as the correct answer. 如果有人能够清楚地告诉我原因,则将其标记为正确答案。

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. 如果已将其注册到http:// localhost:3000 / ,则应使用用于回调的域localhost。 And if you have registered it as http://127.0.0.1:3000/ then you should work with 127... 如果您将其注册为http://127.0.0.1:3000/,则应该使用127 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM