我在哪里可以调用chrome.identity.getAuthToken()来获取有效的令牌? [英] Where can I invoke chrome.identity.getAuthToken() to get a valid token?

查看:207
本文介绍了我在哪里可以调用chrome.identity.getAuthToken()来获取有效的令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google帐户作为身份开发Chrome扩展程序。我正在 http://developer.chrome.com/extensions/app_identity.html



我确定client_id和扩展名id是关联的。然而,我不知道什么时候调用chrome.extension.getAuthToken()。我在onInstalled事件(在我的扩展后台页面上)调用它,但得到一个undefined 令牌回来没有任何错误。 (同样,从后台页面调用它可以得到相同的结果)

由于getAuthToken()可能需要UI(当交互设置为true时),我猜测也许它不能从背景页面调用。如果是这样,何时何地应该从扩展中调用chrome.identity.getAuthToken()?解析方案

结果你可以调用从背景页面getAuthToken()。显示的授权用户界面是一个对话框,而不是一个普通的html页面,所以我想这是允许从背景页面。



FWIW,我的问题是没有给出产品名称,因为我使用的是旧的Google API测试帐户。您需要在'新'云开发者控制台中的同意屏幕下或在旧控制台中的编辑品牌信息下给出名称。



神秘的糟糕的client_id {0}错误,否则!


I'm trying to develop a chrome extension using Google Accounts as the identity. I'm following the tutorial at http://developer.chrome.com/extensions/app_identity.html

I made sure the client_id and the extension id are associated. However, I'm not sure when to call chrome.extension.getAuthToken()

I call it at onInstalled event (on my extension background page) but get an "undefined" token back without any error. (Likewise calling it from the background page console yields the same result)

Since getAuthToken() may require a UI (when interactive is set to true), I'm guessing perhaps it cannot be called from a background page. If so, when and where should chrome.identity.getAuthToken() be called from an extension?

解决方案

Turns out you can call getAuthToken() from the background page. The authorization UI shown is a dialog box, not a regular html page, so I guess that's allowed from the background page.

FWIW, my problem was not giving a "Product name", since I was using an old google api test account. You need to give a name under "Consent screen" in the 'new' cloud developers console, or under "Edit Branding Info" in the old console.

You get a cryptic "bad client_id {0}" error otherwise!

这篇关于我在哪里可以调用chrome.identity.getAuthToken()来获取有效的令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆