【问题标题】:Is it possible to make oauth 2.0 requests using background page of chrome extensions?是否可以使用 chrome 扩展的背景页面发出 oauth 2.0 请求?
【发布时间】:2012-08-14 10:12:04
【问题描述】:

我在调用 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()) 从未进行过,我也没有收到令牌。是不是因为我是从后台页面调用它而身份验证窗口无法发回响应?

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

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

【问题讨论】:

    标签: google-chrome-extension oauth-2.0 google-api-client


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多