how to get chrome.identity.getAuthToken() working?

8,300 views
Skip to first unread message

Cyrus Adkisson

unread,
Mar 16, 2014, 11:12:50 PM3/16/14
to chromium-...@chromium.org
Hey guys, I'm struggling to get chrome.identity.getAuthToken() working in my extension. Here's what I've done so far.

1. Created my Oauth2 app in the google developers API console.

2.  Modified my manifest json to include the installed key value and the "oauth2": {"client_id": "blah", "scopes":["blah"]}. (I know my key/client_id are working because I plugged them into the chrome-apps-samples/identity app with success.)

3. Added a button which executes the following event on click:

$("#google_login_link").click(
function () {
console.log("Identity:", chrome.identity);
chrome.identity.getAuthToken({ 'interactive': false },function (token) {
alert("back token=" + token);
console.log("Identity:", chrome.identity);
});
});

All that happens on click is the alert fires with token=undefined. And the console looks like the attached image.

------------

If I change "interactive" to true, when I click the button I'm redirected to chrome://settings with the red/pink box that says my account sign in details are out of date. (See attached). If I sign in again, it goes right back to chrome://settings and after a few seconds, the red/pink box reappears (even though I KNOW I'm putting in the right login info. The same login info works fine elsewhere on google.) 

Sooo... I'm confused as to what is going on.

First, why is token undefined in the first situation? 
Second, what does the console log output mean? 
Third, why am I being redirected to chrome://settings? 
Fourth, why doesn't my login information work?

Any help would be greatly appreciated.
console.jpg
settings.jpg

Cyrus Adkisson

unread,
Mar 18, 2014, 3:08:56 PM3/18/14
to chromium-...@chromium.org
Solved.

The main issue here was the type of application I had set up in the Google Developer API Console. I had previously used an "installed app" under the "desktop" variety. Once I switched to a "chrome app", things got better. For my purposes, I had to enable the Google+ api as well to make sure it was all working properly.

And for those that might be unclear (as I was), using chrome.identity.getAuthToken still allows the user to "log in" to your app. They get the auth token, pass it to your backend, your backend looks up their email address (with the correct permissions) and issues login credentials for your app, specifically. 

FWIW, the login flow with chrome.identity.getAuthToken is much nicer for the user and simpler for the developer. 

Cyrus

Cyrus Adkisson

unread,
Apr 14, 2014, 12:30:21 PM4/14/14
to chromium-...@chromium.org
I've had a change of heart about getAuthToken being better since I wrote the last message and went back to the normal auth flow. Three reasons:

1. The overlay that pops up is pretty bad UI/UX. It appears pretty much wherever it feels like on the screen (having nothing to do with the browser) and appears like a malicious popup you'd expect on a torrent or porn site. I've come to feel that it's too jarring and confusing for the user to be acceptable.

2. This may only be a developer problem, but if I want to switch accounts inside my extension, going with getAuthToken makes that more difficult because the accounts are tied into Chrome itself. For instance, if I am a developer testing interaction between two users, if I want to switch from user A to user B, I have to not only switch in the app, but switch Chrome users as well. And these dummy users will need to have chrome sync and all that. The weird overlay doesn't, from what I can tell, allow easy user switching. The current user seems hardcoded at the top right.

3. I've got other 3rd party logins in the extension, too. Having this the getAuthToken flow be so different is weird from a UI/UX perspective. Whereas reason #1 above was "the UX is bad in a absolute sense", what I'm saying here is "it's even worse when the UX of your other auth flows is different". This is true, not only for the user, but for the developer, too.

The auto-refreshing of tokens is nice and all that and I understand there are advantages, but, IMO and in my special case, the getAuthToken system isn't acceptable in practice.

Cyrus

Ashish Mehrotra

unread,
Apr 27, 2014, 4:26:50 AM4/27/14
to chromium-...@chromium.org
chrome.identity is a very unstable API.
Anything that works in development doesnt work in production.
I have faced this issue even with the sample apps and with my extension.
Both work just fine when loaded in developer mode but not when bundled and put in web store.
Same/different client id with packaged Chrome app type - failing when used from the web store.

Has anyone made it work ?

Henry Erich III

unread,
May 3, 2014, 2:48:40 PM5/3/14
to chromium-...@chromium.org
I had to deploy mine to the store. Then install it from the store. Then get the key from the manifest.json that the store installed and add it to my dev manifest.json. After that it works proper in dev.


On Sunday, March 16, 2014 11:12:50 PM UTC-4, Cyrus Adkisson wrote:

Ashish Mehrotra

unread,
May 3, 2014, 4:20:00 PM5/3/14
to Henry Erich III, chromium-...@chromium.org
Hi Henry,

It has been working fine all along in dev (whenever i deploy the extn in dev mode). The problem is in production where you cant mention a key in manifest.json.
If identity has worked for you in production, please let me know how it worked for you.

Sent from my iPhone
--
You received this message because you are subscribed to a topic in the Google Groups "Chromium-extensions" group.
To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/chromium-extensions/HMe3mqCRObc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/42b4b84a-5f57-496f-9c00-f82930d827ba%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Jude Osborn

unread,
May 14, 2014, 11:11:53 PM5/14/14
to chromium-...@chromium.org, Henry Erich III
Is chrome.identity still working? No matter what I do (with chrome extensions) I get a token of undefined. I've checked and double checked my appid, scope and clientId, but no success.

Jude Osborn

unread,
May 14, 2014, 11:49:08 PM5/14/14
to chromium-...@chromium.org
My Chrome version number is 35.0.1916.86 beta. I also tried on 37.0.1991.0 canary. Same problem. 

I also tried out the chrome app identity example and I get an "invalid credentials" message. Not sure if this is the same problem, though -- it's possible the credentials used for this sample are actually invalid. Just thought I'd mention it. 

Ben Wells

unread,
May 14, 2014, 11:52:12 PM5/14/14
to Jude Osborn, Michael Courage, Chromium-extensions
+courage who might have some ideas.


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Jude Osborn

unread,
May 19, 2014, 8:50:58 PM5/19/14
to Michael Courage, Chromium-extensions, Ben Wells
Oddly enough, identity is working fine now a few days later. Just fired up the Identity API sample and now it’s returning a token. No idea what changed, but I can confirm identity is working.

Emily Taylor

unread,
Jun 13, 2014, 7:08:40 PM6/13/14
to chromium-...@chromium.org, cou...@google.com, benw...@chromium.org
I can't get chrome.identity.getAuthToken() to work at ALL.

Initially, I was using my own application, but now I'm using the 'identity' sample @ https://github.com/GoogleChrome/chrome-app-samples/tree/master/identity as a test.

I've uploaded this to the Chrome store 3 times and then downloaded to get a generated key from the manifest.json.

For each key I've created, I've created a Client ID for Chrome application in the API console using the extension ID associated with the key.

When I update the "key" and the "client_id" in the sample's manifest.json locally and add as an unpacked extension, I consistently get: {"message":"OAuth2 request failed: Service responded with error: 'bad client id: {0}'"}

I've never had any trouble with chrome.identity.launchWebAuthFlow in the past.  I'm really fed up.  I'm about at the point where I'll use launchWebAuthFlow for my Google auth instead, but I would *LOVE* to get 1 MVP of chrome.identity.getAuthToken() working.

Any thoughts?  TIA
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Emily Taylor

unread,
Jun 18, 2014, 10:25:03 PM6/18/14
to chromium-...@chromium.org, cou...@google.com, benw...@chromium.org
AH HA!  To make it work, I needed to set the "Product name" field under "Consent screen" for my product in the API console.  Otherwise I kept getting "bad client id"


Andy Kenward

unread,
Jun 19, 2014, 9:53:59 AM6/19/14
to chromium-...@chromium.org, cou...@google.com, benw...@chromium.org
Thank you for that post. Solved my issue. 

ashish

unread,
May 29, 2015, 6:15:21 AM5/29/15
to chromium-...@chromium.org, cou...@google.com, andyk...@gmail.com, benw...@chromium.org
Hi All

I would like to implement an equivalent function for "chrome.identity.getAuthToken()" in python. My objective is to get auth token in non-interactive mode. I mean, instead of redirecting a page to enter login credential, I would like to pass login credentials some where in the query. Is is possible ? I would like to do this to automate auth token generation --> app registration using auth token . While automating this, no user interactive should be there.

Thank you in advance for your help !

Regards
Ashish

Lucas Smolic

unread,
Aug 6, 2020, 1:55:21 PM8/6/20
to Chromium Extensions, cou...@google.com, benw...@chromium.org, andyk...@gmail.com
Just an FYI to you and all newcomers... They broken this again in a different way.


According to this post, they haven't found a way to literally render the "key" for your app on the new dashboard. I spend nearly 12 hours trying to resolve this issue you are all talking about and until I found this blog post where they openly admit to now implementing a string literal, I've just been puling my hair out...

Just click on the "Show More" on the little overlay on the bottom of the developer dashboard and click Opt-Out, to bring you to the old listing dashboard. From there you will see the key you need to copy. That key needs to go into your manifest.json so that the whole thing woks at all.

After that you can click on the warning label at the top to Opt-In again to the app. 

I've been following this quickstart and that part about the key turned out to be the...key to it all. But because google always does things half-assed and doesn't care about their dev community (#rant) they completely.

Hope this helps other struggling devs. 

@google... get your shit together. Sick of wasting hours of my life on using your damn docs for basic shit.
Reply all
Reply to author
Forward
0 new messages