如何将Facebook代币与Chrome.Identity一起使用OAuth2



我正在使用Chrome.Sidentity在包装应用程序中使用Facebook的用户令牌。我致电Chrome.Identity.launchwebauthflow,我需要将访问令牌发送给服务器,然后使用访问令牌来验证用户。

与Google 一起工作。但是由于某种原因,它对Facebook不起作用。由于某种原因,Facebook的Oauth似乎很特别。我已经将extensionId.chromiumapp.org添加到API中的重定向URL列表中。添加

"https://extensionid.chromiumapp.org/*",
    "https://facebook.com/*",
    "https://www.facebook.com/dialog/",
    "https://graph.facebook.com/*"

to subtest.json。但是什么都没有改变。

在调用chrome.Identity.launchwebauthflow时,我会使用url

"https://www.facebook.com/dialog/oauth/access_token?" +
                   "client_id=myclientid&client_secret=myclientsecret&" + 
                  "response_type=token&grant_type=client_credentials"

当我尝试调用它时,我会收到以下错误消息:

«launchWebAuthFlow completed Object {message: "Authorization page could not be loaded."} »

当我使用URL时

«"https://www.facebook.com/dialog/oauth?client_id=myclientid&redirect_uri=https://myextensionid.chromiumapp.org/facebook.com=token&scope=user"» 

我得到下一个错误:

«launchWebAuthFlow completed Object {message: "User interaction required."} undefined »

我尝试在4天内获得Facebook令牌。我累了。我做错了什么?为什么Chrome.Identity.GetAuthToken非常适合Google Chrome.Identity.launchwebauthflow与Facebook不使用?

我希望有人做了同样的事情并可以帮助我。

我解决了问题。这是一个示例https://github.com/blackgirl/facebook_oauth2_sample_for_for_extensions

"所需的用户交互"。消息意味着用户需要登录到Facebook,和/或批准所需的OAUTH范围。设置{Interactive:true}标志将允许Identity.launchwebauthflow显示一个窗口,用户将执行这些步骤。由于您正在传递{Interactive:false} flag,identity.lauchwebauthflow失败。

https://www.facebook.com/dialog/oauth很可能是您要使用的URL来开始流程。Client_credentials赠款通常用于您访问应用程序拥有的资源的情况,而不是特定用户拥有的资源。

但是,如果您确实想调试"无法加载授权页"的情况,那么这样做的方法是打开Chrome://Net-Internals,并寻找来自Facebook的错误响应。

chrome.identity.launchWebAuthFlow(
{'url': 'https://www.facebook.com/dialog/oauth?client_id=myclientid&redirect_uri=https://myextensionid.chromiumapp.org/facebook.com=token&scope=user, 'interactive': true},
function(redirect_url) { 
    /* Extract token from redirect_url */ 
    console.log(redirect_url);
});

//'Interactive':true

该标志将做什么,将显示一个询问用户名和密码的对话框 成功登录后,它将要求授予访问权限,只需按一下即可 您将在上述功能主体中收到重定向的URL。

最新更新