mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 23:08:33 +02:00
Added an example using the identity API (#180)
* Added an example using the identity API * Updated with review comment fixes
This commit is contained in:
22
google-userinfo/background/userinfo.js
Normal file
22
google-userinfo/background/userinfo.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
Fetch the user's info, passing in the access token in the Authorization
|
||||
HTTP request header.
|
||||
*/
|
||||
function getUserInfo(accessToken) {
|
||||
const requestURL = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
|
||||
const requestHeaders = new Headers();
|
||||
requestHeaders.append('Authorization', 'Bearer ' + accessToken);
|
||||
const driveRequest = new Request(requestURL, {
|
||||
method: "GET",
|
||||
headers: requestHeaders
|
||||
});
|
||||
|
||||
return fetch(driveRequest).then((response) => {
|
||||
if (response.status === 200) {
|
||||
return response.json();
|
||||
} else {
|
||||
throw response.status;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user