我研究这个问题已经有一段时间了,但没有成功。希望有人能对此有所了解!
我工作的地方认证/授权正在被谷歌的以外进行(谷歌的Chrome扩展(浏览器操作)chrome.identity.launchwebauthflow与interactive设置为true)。我们已经为某些用户(但不是全部)成功进行了身份验证/授权流程。以下是有趣的结果:
chrome-extension://pathofextension)。用户点击授权按钮,成功获取授权码,将其兑换为访问令牌,即可继续使用该应用程序。我们认为这是客户端问题,但我们都使用相同的 Chrome 版本。返回身份验证代码时,什么会导致扩展程序的弹出窗口关闭?我们不能让开发者控制台保持打开状态以查看是否出现任何错误,因为当开发者控制台打开时它工作得很好。我们正在使用$.ajaxSetup({ cache:false })以确保为 ajax 请求禁用缓存。
这是 chrome.identity.launchwebauthflow 调用的片段(最初从弹出窗口调用):
chrome.identity.launchWebAuthFlow({url:url,interactive:true},function(response) {
console.log('OAuth Response: '+response);
if (response) {
var authCode = encodeURIComponent(response.substring(response.indexOf('=')+1));
console.log('Auth Code: '+authCode);
userAuthorization(authCode);
} else {
authorizeButton();
}
});
Run Code Online (Sandbox Code Playgroud)
尝试应用后台代码解决方案后编辑的代码:
弹出脚本现在调用后台脚本:
chrome.runtime.sendMessage({type:'authorize',url:url},function(response) {
console.log(chrome.runtime.lastError);
console.log(response);
if (response && response.authCode) {
userAuthorization(response.authCode); …Run Code Online (Sandbox Code Playgroud)