【问题标题】:Getting the user's google identity from a chrome app从 chrome 应用程序获取用户的谷歌身份
【发布时间】:2016-08-08 10:12:52
【问题描述】:

我以为事情在发生,但我发现在使用 interactive:false 调用 getAuthToken 后出现此错误:

OAuth2 请求失败:服务响应错误:'Bad Request'

'Bad Request' 真的很少告诉我。好的,我知道我可能需要使用 interative:true (为什么?),所以当我尝试这样做时,它会生成我的浏览器,提示我的谷歌登录(我输入它,这真的很痛苦,因为我们有两步身份验证),然后……什么都不做……回调永远不会被调用……

任何有兴趣帮助我的人都可能希望从我的 manifest.json 中查看位:

"key": "MII...QAB",
"oauth2": {
    "client_id": "35...-lnf...1pd.apps.googleusercontent.com",
    "scopes": [ "identity" ]
},
"permissions":[ "identity", "https://accounts.google.com/*", "https://www.googleapis.com/*", "https://*.amazonaws.com/*", "<all_urls>" ],

您可能还想查看相关代码:

chrome.identity.getAuthToken({ 'interactive': true, 'scopes':['identity'] }, function ( token ) {
    if ( chrome.runtime.lastError ) {
        next(chrome.runtime.lastError);
    } else {
        next( null, token );
    }
});

或者,或者:

chrome.identity.getAuthToken({ 'interactive': false }, function ( token ) {
    if ( chrome.runtime.lastError ) {
        next(chrome.runtime.lastError);
    } else {
        next( null, token );
    }
});

我很乐意提供任何其他可能有助于确定我哪里出错的信息。

【问题讨论】:

  • 这意味着与浏览器已经登录的 chrome 会话(在 chrome://settings 上登录的会话)一起使用,如果您已经在那里登录,它将允许单击授权.
  • @kzahel :是的,我理解那部分。它确实提示我登录(尽管我已经登录)......然后它什么也不做,除非我设置 interactive:false 否则永远不会调用回调(带令牌)......然后它告诉我“错误请求” (没有足够的信息继续......)

标签: javascript google-chrome-app google-identity


【解决方案1】:

Chrome documentation 中说明了交互式对象中布尔值的用途/含义,获取令牌可能需要用户登录 Chrome,或批准应用程序请求的范围。如果interactive 标志是truegetAuthToken 将根据需要提示用户。当标志为false 或省略时,getAuthToken 将在需要提示时返回失败。

现在你的错误OAuth2 request failed: Service responded with error: 'Bad Request'

确保在创建 OAuth 凭据时在同意屏幕中提供电子邮件地址和产品名称。

欲了解更多信息,请查看此thread

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多