【问题标题】:Facebook : URL blocked This redirect failed because the redirect URI is not white-listed in the app's client OAuth settingsFacebook:URL 被阻止此重定向失败,因为重定向 URI 未在应用程序的客户端 OAuth 设置中列入白名单
【发布时间】:2021-02-20 00:06:21
【问题描述】:

最近我在我的网站中使用了 Facebook 登录选项。我已经编写了所有需要的 API,并在使用“localhost”作为域时对它们进行了彻底的测试。在 Facebook 开发者帐户中配置我的 APP 中的设置时,我已经设置了所有必要的设置,例如提供 Oauth 重定向 URL、在基本设置中添加域名等。那时一切都很好。因此,我请求了所需的应用权限,例如 pages_manage_posts、pages_read_enagagment、pages_show_list 并申请了它们。 Facebook 在应用审查中批准了他们。 我在 Facebook 中使用的重定向 URL(“https://execute.app/#/socialmedia/management/”)正确放入 Facebook Oauth 重定向 URL 路径,如下图所示。

我已将服务器端 API 用于 Facebook 登录和图形 API。我使用 Oauth2 进行 Facebook 登录。可以看下面的代码

var OAuth2 = require('oauth').OAuth2;
var oauth2 = new OAuth2(CONSTANTS.FB_APP_Key,
  CONSTANTS.FB_APP_Secret,
  "", "https://www.facebook.com/dialog/oauth",
  "https://graph.facebook.com/oauth/access_token",
  null);
  
  app.get('/api/document/facebook/auth', function (req, res) {
  var redirect_uri = "https://execute.app/#/socialmedia/management/";
  console.log("redirect_uri ", redirect_uri);
  var params = { 'redirect_uri': redirect_uri, 'scope': 'email,public_profile,pages_manage_posts,pages_show_list,pages_read_engagement' };
  var authUrl = oauth2.getAuthorizeUrl(params);
  res.send({
    "status": true,
    "message": "login url generated successfully",
    "url": authUrl
  });
});
我将在下面的两个场景中解释这个问题。
 Scenario-1: When there is and existing active Facebook session in browser i.e, when some user is already logged into Facebook in facebook.com or developers.facebook.com and when we try to login into Facebook from our website, Oauth Authentication API gets called and returns Facebook login URL with status code 200 and the url gets opened in a new tab, its works fine, we don't need to enter Facebook login credentials again, we can just click on "**Continue as USER**" button and then we get the login code, with which we can get user access token. After getting token everything works as planned.

 Scenario-2: But if no user is already logged into Facebook in browser and when I click on **login to Facebook** button, API call is made and it returns login URL, but the response status code sent by Oauth login API is 304. A new Facebook login tab is opened, but there is a warning displaying a message saying "URL blocked.

此重定向失败,因为重定向 URI 未在应用的客户端 OAuth 设置中列入白名单。确保客户端和 Web OAuth 登录已打开,并将您的所有应用程序域添加为有效的 OAuth 重定向 URI。”

但是您可以看到我已经在 Facebook 中添加了正确的重定向 URL。正如我上面提到的,它在场景 1 中有效,在另一个场景中无效。

注意:无论状态码是 200 还是 304,Oauth Authentication API 返回的 Facebook 登录 URL 都是一样的。它是“https://www.facebook.com/dialog/oauth?redirect_uri=https%3A%2F%2Fexecute.app%2F%23%2Fsocialmedia%2Fmanagement%2F&scope=email%2Cpublic_profile%2Cpages_manage_posts%2Cpages_show_list%2Cpages_read_engagement&client_id=88XXXXXXX663"

请帮我解决这个问题,在此先感谢

【问题讨论】:

  • 我的猜测 - 它可能与 URL 中使用的 # 有关。如果他们在重定向过程中的任何地方都没有正确处理 URL 编码,那么这很容易“破坏”您尝试在此处传递的实际 URL 值。最佳解决方法 - 不再将此类老式 URL 用于 SPA。 HTML5 History API 存在。

标签: node.js facebook facebook-graph-api oauth-2.0 facebook-login


【解决方案1】:

OAuth RFC 表示重定向 URI:

端点 URI 不得包含片段组件。

这可能是 Facebook 中的一个错误,它适用于某些场景而不适用于其他场景,但实际上最好避免使用带有片段组件的 URI。如果 Facebook 的文档声明您可以将重定向 URI 与片段一起使用,我会尝试与他们联系,询问为什么这在某些情况下不起作用。

【讨论】:

    猜你喜欢
    • 2019-07-23
    • 2017-09-09
    • 2018-09-03
    • 2018-06-26
    • 2020-03-27
    • 2019-05-19
    相关资源
    最近更新 更多