Skip to content

Commit

Permalink
Merge pull request #13 from SnickerdoodleLabs/Popup-OAuth
Browse files Browse the repository at this point in the history
Popup and OAuth implementation
  • Loading branch information
meera-datey authored Jun 7, 2022
2 parents 15a9dc5 + ade08b5 commit ee79336
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 179 deletions.
29 changes: 29 additions & 0 deletions 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.
62 changes: 40 additions & 22 deletions packages/browserExtension/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
"default_popup": "popup.html",
"default_icon": "icon-34.png"
},
"oauth2": {
"client_id": "1055144164647-mfcem81s96av4o1gi6mrmcrqfmbrj5i4.apps.googleusercontent.com",
"scopes": [
"profile email",
"https://www.googleapis.com/auth/contacts",
"https://www.googleapis.com/auth/contacts.readonly",
"https://www.googleapis.com/auth/directory.readonly",
"https://www.googleapis.com/auth/profile.agerange.read",
"https://www.googleapis.com/auth/profile.emails.read",
"https://www.googleapis.com/auth/profile.language.read",
"https://www.googleapis.com/auth/user.addresses.read",
"https://www.googleapis.com/auth/user.birthday.read",
"https://www.googleapis.com/auth/user.emails.read",
"https://www.googleapis.com/auth/user.gender.read",
"https://www.googleapis.com/auth/user.organization.read",
"https://www.googleapis.com/auth/user.phonenumbers.read",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"


]
},

"permissions": [
"notifications",
Expand All @@ -22,26 +44,22 @@
"icons": {
"128": "icon-128.png"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*", "<all_urls>"],
"js": ["contentScript.bundle.js"],
"css": ["content.styles.css"],
"run_at": "document_end"
}
],
"content_scripts": [{
"matches": ["http://*/*", "https://*/*", "<all_urls>"],
"js": ["contentScript.bundle.js"],
"css": ["content.styles.css"],
"run_at": "document_end"
}],
"devtools_page": "devtools.html",
"web_accessible_resources": [
{
"resources": [
"content.styles.css",
"icon-128.png",
"icon-34.png",
"shadowScript.js",
"injectables/*",
"assets/*"
],
"matches": ["<all_urls>"]
}
]
}
"web_accessible_resources": [{
"resources": [
"content.styles.css",
"icon-128.png",
"icon-34.png",
"shadowScript.js",
"injectables/*",
"assets/*"
],
"matches": ["<all_urls>"]
}]
}
81 changes: 57 additions & 24 deletions packages/browserExtension/src/pages/Background/index.js
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);
}
});
Loading

0 comments on commit ee79336

Please sign in to comment.