Skip to content

Commit 5d8b942

Browse files
authored
Add Edge extension (#106)
1 parent a87f6a5 commit 5d8b942

11 files changed

Lines changed: 112 additions & 32 deletions

extension/shared/utils/auth/facebook/getFacebookAccessToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const getFacebookAccessToken = async (code: string) => {
99
response = await fetch(
1010
`https://graph.facebook.com/v17.0/oauth/access_token?client_id=${process.env.REACT_APP_FACEBOOK_CLIENT_ID}&client_secret=${process.env.REACT_APP_FACEBOOK_CLIENT_SECRET}&code=${code}&redirect_uri=https://ijdehllahgkhhcoffcohgmbebcchdknb.chromiumapp.org/callback`
1111
)
12-
} else if (browserName === 'firefox') {
12+
} else if (browserName === 'firefox' || browserName === 'edge') {
1313
const redirectUrl = browser.identity.getRedirectURL()
1414
response = await fetch(
1515
`https://graph.facebook.com/v17.0/oauth/access_token?client_id=${process.env.REACT_APP_FACEBOOK_CLIENT_ID}&client_secret=${process.env.REACT_APP_FACEBOOK_CLIENT_SECRET}&code=${code}&redirect_uri=${redirectUrl}`

extension/shared/utils/auth/facebook/getFacebookAuthParams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const getFacebookAuthParams =
3333
}
3434
)
3535
})
36-
} else if (browserName === 'firefox') {
36+
} else if (browserName === 'firefox' || browserName === 'edge') {
3737
const redirectUrl = browser.identity.getRedirectURL()
3838
const returnedUrl = await browser.identity.launchWebAuthFlow({
3939
interactive: true,

extension/shared/utils/auth/getBrowser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ export const getBrowser = () => {
44
const manifest = browser.runtime.getManifest()
55
const isChrome = manifest.short_name === 'BrowseGPT - Chrome'
66
const isFirefox = manifest.short_name === 'BrowseGPT - Firefox'
7+
const isEdge = manifest.short_name === 'BrowseGPT - Edge'
78

89
if (isChrome) return 'chrome'
910
if (isFirefox) return 'firefox'
11+
if (isEdge) return 'edge'
12+
1013
return null
1114
}

extension/shared/utils/auth/github/getGithubAccessToken.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ export const getGithubAccessToken = async (code: string) => {
2626
},
2727
}
2828
)
29+
} else if (browserName === 'edge') {
30+
const redirectUrl = browser.identity.getRedirectURL()
31+
response = await fetch(
32+
`https://github.com/login/oauth/access_token?client_id=${process.env.REACT_APP_GITHUB_CLIENT_ID_EDGE}&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET_EDGE}&code=${code}&redirect_uri=${redirectUrl}`,
33+
{
34+
method: 'POST',
35+
headers: {
36+
Accept: 'application/json',
37+
},
38+
}
39+
)
2940
}
3041

3142
if (response.ok) {

extension/shared/utils/auth/github/getGithubAuthParams.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ export const getGithubAuthParams = async (): Promise<GithubAuthURLParams> => {
4343
code: params.get('code'),
4444
state: params.get('state'),
4545
}
46+
} else if (browserName === 'edge') {
47+
const redirectUrl = browser.identity.getRedirectURL()
48+
const returnedUrl = await browser.identity.launchWebAuthFlow({
49+
interactive: true,
50+
url: `https://github.com/login/oauth/authorize?scope=user&client_id=${process.env.REACT_APP_GITHUB_CLIENT_ID_EDGE}&state=${process.env.REACT_APP_STATE_SECRET}&redirect_uri=${redirectUrl}`,
51+
})
52+
const params = new URLSearchParams(returnedUrl.split('?')[1])
53+
return {
54+
code: params.get('code'),
55+
state: params.get('state'),
56+
}
4657
}
4758
} catch (error) {
4859
console.error(error)

extension/shared/utils/auth/google/getGoogleAuthToken.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export const getGoogleAuthToken = async (): Promise<string> => {
1616
})
1717
})
1818
} else if (browserName === 'firefox') {
19-
const redirectUrl =
20-
'http://127.0.0.1/mozoauth2/0b27ac2676056462b492c4301381b40613ddeaaf'
19+
const redirectUrl = browser.identity.getRedirectURL()
2120
const returnedUrl = await browser.identity.launchWebAuthFlow({
2221
interactive: true,
2322
url: `https://accounts.google.com/o/oauth2/v2/auth?client_id=${process.env.REACT_APP_GOOGLE_CLIENT_ID_FIREFOX}&redirect_uri=${redirectUrl}&response_type=token&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&state=${process.env.REACT_APP_STATE_SECRET}`,
@@ -27,6 +26,19 @@ export const getGoogleAuthToken = async (): Promise<string> => {
2726
const token = params.get('access_token')
2827
const state = params.get('state')
2928

29+
if (state === process.env.REACT_APP_STATE_SECRET) return token
30+
return null
31+
} else if (browserName === 'edge') {
32+
const redirectUrl = browser.identity.getRedirectURL()
33+
const returnedUrl = await browser.identity.launchWebAuthFlow({
34+
interactive: true,
35+
url: `https://accounts.google.com/o/oauth2/v2/auth?client_id=${process.env.REACT_APP_GOOGLE_CLIENT_ID_EDGE}&redirect_uri=${redirectUrl}&response_type=token&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&state=${process.env.REACT_APP_STATE_SECRET}`,
36+
})
37+
38+
const params = new URLSearchParams(returnedUrl.split('#')[1])
39+
const token = params.get('access_token')
40+
const state = params.get('state')
41+
3042
if (state === process.env.REACT_APP_STATE_SECRET) return token
3143
return null
3244
}

extension/shared/utils/auth/google/getGoogleProfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const getGoogleProfile = async (token: string): Promise<User> => {
4040
}
4141

4242
return null
43-
} else if (browserName === 'firefox') {
43+
} else if (browserName === 'firefox' || browserName === 'edge') {
4444
const response = await fetch(
4545
`https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses&key=${process.env.REACT_APP_GOOGLE_PEOPLE_API_KEY}`,
4646
{

extension/webpack.config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ const commonConfig = (extension: string, mode: Mode): Configuration => ({
7979
'process.env.REACT_APP_GOOGLE_CLIENT_ID_FIREFOX': JSON.stringify(
8080
process.env.REACT_APP_GOOGLE_CLIENT_ID_FIREFOX
8181
),
82+
'process.env.REACT_APP_GOOGLE_CLIENT_ID_EDGE': JSON.stringify(
83+
process.env.REACT_APP_GOOGLE_CLIENT_ID_EDGE
84+
),
8285
'process.env.REACT_APP_GOOGLE_CLIENT_SECRET_FIREFOX':
8386
JSON.stringify(
8487
process.env.REACT_APP_GOOGLE_CLIENT_SECRET_FIREFOX
8588
),
89+
'process.env.REACT_APP_GOOGLE_CLIENT_SECRET_EDGE': JSON.stringify(
90+
process.env.REACT_APP_GOOGLE_CLIENT_SECRET_FEDGE
91+
),
8692
'process.env.REACT_APP_GOOGLE_PEOPLE_API_KEY': JSON.stringify(
8793
process.env.REACT_APP_GOOGLE_PEOPLE_API_KEY
8894
),
@@ -99,6 +105,12 @@ const commonConfig = (extension: string, mode: Mode): Configuration => ({
99105
JSON.stringify(
100106
process.env.REACT_APP_GITHUB_CLIENT_SECRET_FIREFOX
101107
),
108+
'process.env.REACT_APP_GITHUB_CLIENT_ID_EDGE': JSON.stringify(
109+
process.env.REACT_APP_GITHUB_CLIENT_ID_EDGE
110+
),
111+
'process.env.REACT_APP_GITHUB_CLIENT_SECRET_EDGE': JSON.stringify(
112+
process.env.REACT_APP_GITHUB_CLIENT_SECRET_EDGE
113+
),
102114
'process.env.REACT_APP_FACEBOOK_CLIENT_ID': JSON.stringify(
103115
process.env.REACT_APP_FACEBOOK_CLIENT_ID
104116
),
@@ -149,7 +161,7 @@ const devConfig = (extension: string): Configuration => ({
149161
path: path.join(__dirname, `${extension}/dist`),
150162
},
151163
watchOptions: {
152-
ignored: ['**/node_modules', '**/dist', '**/build'],
164+
ignored: ['**/node_modules', '**/dist', '**/build', '**/packages'],
153165
},
154166
})
155167

package-lock.json

Lines changed: 54 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"wait-on": "^7.0.1",
2828
"web-ext": "^7.6.2"
2929
}
30-
}
30+
}

0 commit comments

Comments
 (0)