Skip to content

Commit fb6a7ed

Browse files
committed
add login through google auth
1 parent fcb9f95 commit fb6a7ed

13 files changed

Lines changed: 154 additions & 44 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
LAMBDA_URL="ask_url_from_arjadgohar14@gmail.com"
2+
GOOGLE_AUTH_CLIENT_ID=""

dist/.DS_Store

0 Bytes
Binary file not shown.

dist/assets/.DS_Store

0 Bytes
Binary file not shown.

dist/background.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/manifest.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"manifest_version": 3,
33
"name": "I Notes",
4-
"version": "1.7.8",
4+
"version": "1.7.9",
55
"description": "i Notes is a lightweight, easy-to-use extension for taking quick notes, saving developer commands",
66
"permissions": [
77
"storage",
88
"notifications",
9-
"alarms"
9+
"alarms",
10+
"identity"
11+
1012
],
1113
"action": {
1214
"default_popup": "popup.html"
@@ -29,5 +31,10 @@
2931
"matches": ["<all_urls>"],
3032
"js": ["content.js"]
3133
}
32-
]
34+
],
35+
"oauth2": {
36+
"client_id": "112404701625-va4cnbnnlhm68kcv248rs91plojci4at.apps.googleusercontent.com",
37+
"scopes": ["profile", "email"]
38+
}
39+
3340
}

dist/settings.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/.DS_Store

0 Bytes
Binary file not shown.

public/assets/.DS_Store

0 Bytes
Binary file not shown.

public/background.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,57 @@ chrome.alarms.onAlarm.addListener((alarm) => {
1717
});
1818

1919
});
20+
21+
chrome.runtime.onInstalled.addListener(() => {
22+
console.log("I Notes extension installed");
23+
});
24+
25+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
26+
if (message.action === "startGoogleLogin") {
27+
const clientId = process.env.GOOGLE_AUTH_CLIENT_ID;
28+
const redirectUri = chrome.identity.getRedirectURL();
29+
const scopes = ["profile", "email"].join(" ");
30+
31+
const authUrl =
32+
`https://accounts.google.com/o/oauth2/auth` +
33+
`?client_id=${clientId}` +
34+
`&response_type=token` +
35+
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
36+
`&scope=${encodeURIComponent(scopes)}`;
37+
38+
chrome.identity.launchWebAuthFlow(
39+
{ url: authUrl, interactive: true },
40+
(redirectUrl) => {
41+
if (chrome.runtime.lastError || !redirectUrl) {
42+
console.error("Login failed:", chrome.runtime.lastError);
43+
return;
44+
}
45+
46+
const urlFragment = new URLSearchParams(redirectUrl.split("#")[1]);
47+
const accessToken = urlFragment.get("access_token");
48+
49+
if (!accessToken) {
50+
console.error("No access token found.");
51+
return;
52+
}
53+
54+
// Fetch user profile using the access token
55+
fetch("https://www.googleapis.com/oauth2/v2/userinfo", {
56+
headers: {
57+
Authorization: `Bearer ${accessToken}`,
58+
},
59+
})
60+
.then((res) => res.json())
61+
.then((profile) => {
62+
chrome.storage.local.set({ userProfile: profile }, () => {
63+
console.log("User profile saved.");
64+
});
65+
chrome.runtime.sendMessage({ action: "refreshPopup" });
66+
})
67+
.catch((error) => {
68+
console.error("Failed to fetch user profile:", error);
69+
});
70+
}
71+
);
72+
}
73+
});

public/manifest.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"manifest_version": 3,
33
"name": "I Notes",
4-
"version": "1.7.8",
4+
"version": "1.7.9",
55
"description": "i Notes is a lightweight, easy-to-use extension for taking quick notes, saving developer commands",
66
"permissions": [
77
"storage",
88
"notifications",
9-
"alarms"
9+
"alarms",
10+
"identity"
11+
1012
],
1113
"action": {
1214
"default_popup": "popup.html"
@@ -29,5 +31,10 @@
2931
"matches": ["<all_urls>"],
3032
"js": ["content.js"]
3133
}
32-
]
34+
],
35+
"oauth2": {
36+
"client_id": "112404701625-va4cnbnnlhm68kcv248rs91plojci4at.apps.googleusercontent.com",
37+
"scopes": ["profile", "email"]
38+
}
39+
3340
}

0 commit comments

Comments
 (0)