To retrieve the email address and a unique ID, you can utilize chrome.identity.getProfileUserInfo()
. Ensure to include the identity.email
permission along with identity
. No OAuth2 token or network connection is necessary for this method.
Below is a basic extension that displays this data in the console of a background page:
manifest.json
{
"manifest_version" : 2,
"name" : "Identity Test",
"version" : "0.1",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"identity",
"identity.email"
]
}
background.js
chrome.identity.getProfileUserInfo(function(userInfo) {
console.log(JSON.stringify(userInfo));
});
Alternatively, you can fetch user info by utilizing the Google API with an OAuth2 token. Make sure to specify both the profile
and email
scopes. If you opt for the Google API Client library, you can use gapi.client.oauth2.userinfo.get()
. While this strictly adheres to your request of using OAuth and avoiding added permissions, it seems that
chrome.identity.getProfileUserInfo()
is likely what you need.