Facebook:URL 被阻止此重定向失败,因为重定向 URI 未在应用程序的客户端 OAuth 设置中列入白名单
Facebook : URL blocked This redirect failed because the redirect URI is not white-listed in the app's client OAuth settings
最近我在我的网站上使用了 Facebook 登录选项。我已经编写了所有需要的 APIs 并在使用“localhost”作为域时对它们进行了彻底的测试。在我的 Facebook 开发者帐户中的应用程序中配置设置时,我已经设置了所有必要的设置,如提供 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 认证 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"
请帮助我解决这个问题,在此先感谢
重定向 URI 的 OAuth RFC 声明:
The endpoint URI MUST NOT include a fragment component.
这可能是 Facebook 中的一个错误,它适用于某些场景而不适用于其他场景,但实际上最好避免带有片段组件的 URI。如果 Facebook 的文档声明您可以将重定向 URI 与片段一起使用,我会尝试联系他们询问为什么这在某些情况下不起作用。
最近我在我的网站上使用了 Facebook 登录选项。我已经编写了所有需要的 APIs 并在使用“localhost”作为域时对它们进行了彻底的测试。在我的 Facebook 开发者帐户中的应用程序中配置设置时,我已经设置了所有必要的设置,如提供 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 认证 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"
请帮助我解决这个问题,在此先感谢
重定向 URI 的 OAuth RFC 声明:
The endpoint URI MUST NOT include a fragment component.
这可能是 Facebook 中的一个错误,它适用于某些场景而不适用于其他场景,但实际上最好避免带有片段组件的 URI。如果 Facebook 的文档声明您可以将重定向 URI 与片段一起使用,我会尝试联系他们询问为什么这在某些情况下不起作用。