using gapi for OAuth 2.0 in Google Chrome Extensions

3,559 views
Skip to first unread message

David Fisco

unread,
Mar 22, 2012, 8:56:49 PM3/22/12
to google-api-jav...@googlegroups.com
Am I correct in assuming that gapi cannot obtain an OAuth 2.0 token when the library is used in a Google Chrome extension?  I've tried client IDs for both web and installed applications, but no luck.  Thanks.

Brendan

unread,
Mar 22, 2012, 9:25:12 PM3/22/12
to google-api-jav...@googlegroups.com
That's correct, we've had some issues with Oauth 2.0 and chrome extensions, so it is not currently supported. We are working on it and hope to have it fixed soon, but unfortunately I can't give a more precise estimate.

Sorry for the inconvenience and thanks for your patience!

David Fisco

unread,
Mar 22, 2012, 10:05:50 PM3/22/12
to google-api-jav...@googlegroups.com
Thanks for the quick response, Brendan.  Looking forward to the implementation.

Demetrios Papadopoulos

unread,
May 1, 2012, 6:04:36 PM5/1/12
to google-api-jav...@googlegroups.com
Any news here? This would be very useful.
As of now I am using http://smus.com/oauth2-chrome-extensions/ to obtain an access token. Trying to figure out whether I can use that access token and make authenticated requests through gapi. Anybody has done this before? Thanks in advance.

Brendan

unread,
May 1, 2012, 6:54:21 PM5/1/12
to google-api-jav...@googlegroups.com
Chrome Extension support is still not ready. Unfortunately I cannot give much more info than that.

If you have retrieved an OAuth 2.0 token that you've obtained elsewhere, you can tell the JS Client to use that token with the gapi.auth.setToken method:

gapi.auth.setToken({
  'access_token': 'oauth 2.0 access token'
});

More info on setting tokens and the token object can be found here:  http://code.google.com/p/google-api-javascript-client/wiki/ReferenceDocs#OAuth_2.0_Token_Object 

Michael Debbah

unread,
May 1, 2012, 8:55:05 PM5/1/12
to google-api-jav...@googlegroups.com

Hi Brendan. Just wanted to thank for your help as I didn't do it before. Regards. Michael

Demetrios Papadopoulos

unread,
May 1, 2012, 9:26:17 PM5/1/12
to google-api-jav...@googlegroups.com
Thanks Brendan, I tried this and it worked. Initially I thought I had to fill in all the fields of the Token object for setToken to work, but just setting access_token is enough.

Brendan

unread,
May 2, 2012, 12:38:37 PM5/2/12
to google-api-jav...@googlegroups.com
You're both welcome, I'm glad to help.

Demetrios, thanks for linking the Chrome Extension blog post. No doubt it will be useful to others.

Suji Dhiesh

unread,
Aug 14, 2013, 7:17:13 AM8/14/13
to google-api-jav...@googlegroups.com
Is there any option to remove the token .

Pi-Chuan Chang

unread,
Mar 12, 2014, 5:36:32 PM3/12/14
to google-api-jav...@googlegroups.com
Hi,
this thread is from a while ago. I wonder if gapi for oauth in Google Chrome Extensions works now or not, and where I can find a good example for setup? Thanks!

Theodore Vassilakis

unread,
Apr 11, 2014, 1:39:09 PM4/11/14
to google-api-jav...@googlegroups.com
Hi Brendan - greetings, wondering if you can update the group on whether it's now possible to use the google calendar js api from a chrome extension.

Regards,
Theo

Jacob Rosenthal

unread,
Nov 16, 2014, 10:06:10 PM11/16/14
to google-api-jav...@googlegroups.com
It seems clear identity + xhr is whats used for authentication at this point, Though the tasks example does use a modified version of gapi for calls

It looks like all loading has been removed as that would be impossible in chrome. 

Perhaps loading from local save of the file could be hacked together, but I cant find where any of the js source is hosted except for the minified client.js..

Any kind of update from the dev team on chrome + gapi from would be most welcome.

David Karam

unread,
Mar 3, 2015, 3:06:31 AM3/3/15
to google-api-jav...@googlegroups.com
For me getting the oauth token via Chrome's identity API works well. Then one can

gapi.auth.setToken({
  'access_token': 'token from chrome.identity'
});


https://developer.chrome.com/apps/identity

andre...@analyticspros.com

unread,
Sep 13, 2016, 12:35:57 PM9/13/16
to Google API JavaScript Client, obr...@google.com
Hello! Any updates on Chrome Extension support since these posts? 

I noticed that gapi.auth is now deprecated and gapi.auth2 does not appear to have a setToken() function. Is there a way to use gapi.auth2 for authentication or is chrome.identity and xhr the way to do this for a chrome extension? Thanks!
Reply all
Reply to author
Forward
0 new messages