Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I invoke chrome.identity.getAuthToken() to get a valid token?

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?

like image 319
Chih-Chao Lam Avatar asked Jan 23 '14 00:01

Chih-Chao Lam


People also ask

Where are chrome tokens stored?

The tokens are stored securely by the user's browser, and can then be redeemed in other contexts to confirm the user's authenticity.


1 Answers

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!

like image 144
Chih-Chao Lam Avatar answered Oct 29 '22 16:10

Chih-Chao Lam