1

我在调用 Google api 的 chrome 扩展程序的后台页面中运行了 javascript 代码。下面的代码本质上是请求 oAuth2 令牌。

function init(){
gapi.client.setApiKey(apiKey);
console.log("Initializing...");
gapi.auth.init(function() { setTimeout(authenticate,100)});
}
function authenticate(){
console.log("Initialized. Now AUthenticating");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false},api);    
}

身份验证窗口按预期打开,但是在用户登录并允许我的应用程序后,页面只是冻结。回调 (api()) 从未进行过,我也没有收到令牌。是因为我从后台页面调用它而身份验证窗口无法发送回响应吗?

如果是,解决方法/解决方案是什么?

如果是这样,我该如何解决这个问题?

4

1 回答 1

0

您可以使用Boris Smus 的 OAuth 2.0 Library for Chrome Extension。它在我的扩展中效果很好。

无法在 chrome 扩展中使用 OAuth2.0 的原因:

Chrome 扩展程序无法直接使用 OAuth 2.0 服务器端或客户端流程,因为它们位于 chrome-extension:// URLs

于 2012-08-14T02:12:04.687 回答