-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from SnickerdoodleLabs/Popup-OAuth
Popup and OAuth implementation
- Loading branch information
Showing
7 changed files
with
384 additions
and
179 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/browserExtension/src/assets/img/sdHorizontalLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,68 @@ | ||
console.log('This is the background page.'); | ||
console.log('Put the background scripts here.'); | ||
console.log("This is the background page."); | ||
console.log("Put the background scripts here."); | ||
|
||
let userInfo; | ||
|
||
chrome.identity.getProfileUserInfo((info) => { | ||
userInfo = info | ||
userInfo = info; | ||
}); | ||
|
||
|
||
chrome.runtime.onMessage.addListener( | ||
function(request, sender, sendResponse) { | ||
console.log(sender.tab ? | ||
"from a content script:" + sender.tab.url : | ||
"from the extension"); | ||
if (request.greeting === "hello") | ||
sendResponse({farewell: "goodbye"}); | ||
if ( request.type === "SD_REQUEST_IDENTITY" ) { | ||
sendResponse(userInfo) | ||
} | ||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { | ||
console.log( | ||
sender.tab | ||
? "from a content script:" + sender.tab.url | ||
: "from the extension", | ||
); | ||
if (request.greeting === "hello") sendResponse({ farewell: "goodbye" }); | ||
if (request.type === "SD_REQUEST_IDENTITY") { | ||
sendResponse(userInfo); | ||
} | ||
); | ||
}); | ||
|
||
function showStayHydratedNotification() { | ||
chrome.notifications.create({ | ||
type: 'basic', | ||
iconUrl: 'stay_hydrated.png', | ||
title: 'Time to Hydrate', | ||
message: 'Everyday I\'m Guzzlin\'!', | ||
buttons: [ | ||
{ title: 'Keep it Flowing.' } | ||
], | ||
priority: 0 | ||
type: "basic", | ||
iconUrl: "stay_hydrated.png", | ||
title: "Time to Hydrate", | ||
message: "Everyday I'm Guzzlin'!", | ||
buttons: [{ title: "Keep it Flowing." }], | ||
priority: 0, | ||
}); | ||
} | ||
} | ||
|
||
// Google OAuth2 | ||
const API_KEY = "AIzaSyB4-1qbu_jTBJ6WzB-mQukjJOu-4trvpLQ"; | ||
let user_signed_in = false; | ||
|
||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { | ||
if (request.message === "dataRequest" && request.obj === null) { | ||
let current_userID = "me"; | ||
chrome.identity.getProfileUserInfo( | ||
{ accountStatus: "ANY" }, | ||
function (userInfo) { | ||
console.log(userInfo); | ||
current_userID = userInfo.id; | ||
}, | ||
); | ||
chrome.identity.getAuthToken({ interactive: true }, function (auth_token) { | ||
console.log(auth_token); | ||
console.log(current_userID); | ||
let fetch_url = `https://people.googleapis.com/v1/people:batchGet?resourceNames=people/${current_userID}&personFields=phoneNumbers,addresses,ageRanges,locations,names,locations,genders,birthdays,emailAddresses,biographies,clientData,locales,metadata,photos,userDefined`; | ||
let fetch_options = { | ||
headers: { | ||
Authorization: `Bearer ${auth_token}`, | ||
}, | ||
}; | ||
fetch(fetch_url, fetch_options) | ||
.then((res) => res.json()) | ||
.then((res) => { | ||
console.log("DATA", res.responses[0].person); | ||
chrome.runtime.sendMessage({ | ||
message: "cardData", | ||
userData: res.responses[0].person, | ||
}); | ||
}); | ||
}); | ||
sendResponse(true); | ||
} | ||
}); |
Oops, something went wrong.