I have a Google Chrome extension which needs to be authenticated to access data on my server. On my server I have added OAUTH login which allows the user to sign in through a gmail account (I have configured the redirect url on my server and this works. I can sign in through a google account from a webpage). I have OAuth working on the google chrome extension(https://developer.chrome.com/apps/identity) . I can get an OAuth token.But I am unsure as to how to use this token to login into my account on the server. Could someone please help me out?
5
votes
If you are getting the token (either by interactive or non interactive way), that means your user has been authenticated. You just have to save that token against the email id. This email id you can get by 'getProfileUserInfo' in identity API. Hope I understood your question correctly and thus answered.
- Savaratkar
What backend are you using on your server?
- Matt
2 Answers
0
votes
To access your GMail information from your extension with the access token, you just need to add the token to your request header when making an API call:
Authorization: Bearer <access_token>
For instance, to access your Gmail messages, you can make a simple Ajax call:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.googleapis.com/gmail/v1/users/<userId>/messages');
xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
xhr.onload = function() { console.log(this.response) };
xhr.send();