我正在使用chrome.identity.launchWebAuthFlow从我的Rails应用程序中检索身份验证代码,该应用程序使用Doorkeeper gem(东西的门卫端正在工作)设置为OAuth2提供程序。launchWebAuthFlow回调不会运行,Chrome扩展窗口立即关闭?
所以我送然后要求到我的服务器从Chrome扩展这个方法:
requestGrant: function(){
chrome.identity.launchWebAuthFlow(
{
'url': authService.grantEndPoint(),
'interactive': true
}, function(redirect_url){
/* Extract auth code from redirect_url */
var code = authService.extractCode(redirect_url);
alert(code);
authService.getAccessToken(code);
}); //launchWebAuthFlow ends here
}
而我的服务器收到请求并重定向到
https://<my_chrome_extension_name>.chromiumapp.org/oauth2?code=<access_code_generated_by_oauth>
与发现302。
但是,Chrome扩展会立即关闭,并且launchWebAuthFlow的回调函数不会运行。我知道它没有运行,因为我在回调中调用了alert()(不运行),并向我的服务器发送了另一个访问令牌请求(服务器没有收到请求)。
我认为问题的一部分是,当调用launchWebAuthFlow时,Chrome扩展可能会关闭,因为启动WebAuthFlow的窗口是服务器授权流的Web视图,并且扩展关闭(或仅仅是认证流程通过扩展名显示?)
由于某种原因launchWebAuthFlow的默认行为是根据文档关闭窗口,但回调仍然没有运行。
我怎样才能让回调函数运行,并防止铬扩展窗口关闭?