护照 facebook 身份验证不起作用
Passport facebook authentication not working
我有一个 nodeJS 应用程序 (express),它有一个 facebook 登录。我正在使用此处 passport-facebook 中描述的 passport-facebook 身份验证。几周前我的登录名还可以正常工作,但现在发生了一些变化。我不确定是 Facebook 改变了什么,还是我改变了。我没有触及任何登录代码,所以我怀疑它是 facebook 的一部分。
这是我的验证码:
router.get('/', passport.authenticate('facebook'), function(req, res){
});
router.get('/auth/facebook/callback', passport.authenticate('facebook', {
failureRedirect: '/' }),
function(req, res) {
res.redirect('/calendar');
});
基本上,我希望应用程序从应用程序的根目录自动对用户进行身份验证,然后在身份验证后重定向到 /calendar。
症状如下:如果我尝试进入 root 并且之前没有使用 facebook 登录,那么它将把我带到正常的 facebook 登录屏幕,这是应该的。但是在那个屏幕上,有一个警告:
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。但它们应该都很好: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)。我打开了开发人员工具,在其控制台中看到一条错误消息:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
但是,现在我实际上已经登录了。因为如果我现在转到 root 或 /calendar,它将带我到更正页面并显示我已正确登录。显然登录有效,但重定向和允许 URL 存在一些问题。我只是似乎不知道是什么以及为什么。我正在使用 mongodDB 作为数据库。
我不知道为什么这会奏效,但我找到了解决方案。以前,我将有效的 OAuth 重定向 URI 配置为 http://127.0.0.1:3000/auth/facebook/callback,并且一切正常。现在我将其更改为使用 localhost 而不是 127.0.0.1:3000,这似乎可以解决问题。现在一切都按预期工作,但我不知道为什么。如果有人能清楚地告诉我原因,我会将其标记为正确答案。
这可能是因为您在应用程序中注册了哪个网站。如果您已将其注册到 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/,那么您应该使用 127...
我有一个 nodeJS 应用程序 (express),它有一个 facebook 登录。我正在使用此处 passport-facebook 中描述的 passport-facebook 身份验证。几周前我的登录名还可以正常工作,但现在发生了一些变化。我不确定是 Facebook 改变了什么,还是我改变了。我没有触及任何登录代码,所以我怀疑它是 facebook 的一部分。
这是我的验证码:
router.get('/', passport.authenticate('facebook'), function(req, res){
});
router.get('/auth/facebook/callback', passport.authenticate('facebook', {
failureRedirect: '/' }),
function(req, res) {
res.redirect('/calendar');
});
基本上,我希望应用程序从应用程序的根目录自动对用户进行身份验证,然后在身份验证后重定向到 /calendar。
症状如下:如果我尝试进入 root 并且之前没有使用 facebook 登录,那么它将把我带到正常的 facebook 登录屏幕,这是应该的。但是在那个屏幕上,有一个警告:
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。但它们应该都很好: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)。我打开了开发人员工具,在其控制台中看到一条错误消息:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
但是,现在我实际上已经登录了。因为如果我现在转到 root 或 /calendar,它将带我到更正页面并显示我已正确登录。显然登录有效,但重定向和允许 URL 存在一些问题。我只是似乎不知道是什么以及为什么。我正在使用 mongodDB 作为数据库。
我不知道为什么这会奏效,但我找到了解决方案。以前,我将有效的 OAuth 重定向 URI 配置为 http://127.0.0.1:3000/auth/facebook/callback,并且一切正常。现在我将其更改为使用 localhost 而不是 127.0.0.1:3000,这似乎可以解决问题。现在一切都按预期工作,但我不知道为什么。如果有人能清楚地告诉我原因,我会将其标记为正确答案。
这可能是因为您在应用程序中注册了哪个网站。如果您已将其注册到 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/,那么您应该使用 127...