Chrome App身份登录无效

时间:2016-10-08 22:21:42

标签: javascript google-chrome google-chrome-extension nwjs

我尝试使用chorome.identity来验证我的应用程序,但似乎NWJS无法加载chrome在chrome:// chrome-signin /?access_point = 6& reason = 0时提供的登录页面。 我的package.json就像这样:

 "permissions": ["tabs", "identity", "storage", "https://www.googleapis.com/*",
        "https://*.googleusercontent.com/*",
        "https://ssl.gstatic.com/",
        "https://www.googleapis.com/",
        "https://accounts.google.com/",
        "chrome://chrome-signin/?access_point=6&reason=0"],

    "oauth2": {
        "client_id": "xxxxxx.apps.googleusercontent.com",
        "scopes": [
            "https://www.googleapis.com/auth/drive"
        ]
    },
    "key": "MIIBIjANBxxxxxxx"

这是我的代码:

 chrome.identity.getAuthToken({'interactive': true}, function (token) {
            if (chrome.runtime.lastError) {
                console.log(chrome.runtime.lastError);
                return;
            }

            console.log('Tokennya adalah', token);
        });

我写的代码有错吗?

1 个答案:

答案 0 :(得分:0)

大多数情况下,您的oauth2 client_id与您的扩展程序包ID不匹配。为chrome app生成oauth2令牌时,在您使用清单上传初始应用后,它会询问您应用的网络商店ID。检查它是否与加载到chrome进行开发的扩展名相同。如果没有,请提供本地扩展名而不是网络商店ID。并在清单中使用该client_id进行开发。稍后将其更改为要发布的webstore url id 并且在权限下不需要“chrome:// chrome-signin /?access_point = 6& reason = 0”url。