Skip to content

Commit 5c42591

Browse files
committed
Update OAUTH flow for upcoming Firefox 75
1 parent 4544640 commit 5c42591

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/background/services/AuthService.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ import uuidv4 from 'uuid/v4';
33
import config from '../../common/config';
44
import { getUrlQuery } from '../../common/utils';
55

6-
const redirectUrl = `https://${config.app.id}.chromiumapp.org/`;
6+
const authConfig = config.auths[process.env.BROWSER];
7+
const { clientId, clientSecret } = authConfig;
8+
9+
const redirectUrl = (process.env.BROWSER === 'firefox')
10+
? browser.identity.getRedirectURL()
11+
: `https://${config.app.ids.chrome}.chromiumapp.org/`;
12+
console.log('OAUTH REDIRECT URL', redirectUrl);
713

814
const scope = 'gist';
915
const getAuthUrl = state => 'https://github.com/login/oauth/authorize?' +
10-
`client_id=${encodeURIComponent(config.auth.clientId)}&` +
16+
`client_id=${encodeURIComponent(clientId)}&` +
1117
`scope=${encodeURIComponent(scope)}&` +
1218
`state=${encodeURIComponent(state)}&` +
1319
`redirect_uri=${redirectUrl}`;
1420

1521
const getAccessTokenUrl = (code, state) => 'https://github.com/login/oauth/access_token?' +
16-
`client_id=${encodeURIComponent(config.auth.clientId)}&` +
17-
`client_secret=${encodeURIComponent(config.auth.clientSecret)}&` +
22+
`client_id=${encodeURIComponent(clientId)}&` +
23+
`client_secret=${encodeURIComponent(clientSecret)}&` +
1824
`code=${encodeURIComponent(code)}&` +
1925
`state=${encodeURIComponent(state)}&` +
2026
`redirect_uri=${redirectUrl}`;
@@ -45,10 +51,10 @@ function getAccessToken(code, state) {
4551
}
4652

4753
function revokeAccessToken(accessToken) {
48-
return fetch(`https://api.github.com/applications/${config.auth.clientId}/tokens/${accessToken}`, {
54+
return fetch(`https://api.github.com/applications/${clientId}/tokens/${accessToken}`, {
4955
method: 'DELETE',
5056
headers: {
51-
Authorization: `Basic ${btoa(config.auth.clientId + ':' + config.auth.clientSecret)}`,
57+
Authorization: `Basic ${btoa(clientId + ':' + clientSecret)}`,
5258
},
5359
}).then(response => {
5460
// 404 here just means that the user is already logged out

src/common/config.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@ module.exports = {
22
namespace: 'code-medium-extension',
33

44
app: {
5-
id: 'dganoageikmadjocbmklfgaejpkdigbe',
5+
ids: {
6+
chrome: 'dganoageikmadjocbmklfgaejpkdigbe',
7+
firefox: '{22b7825c-a56f-4978-a9db-aa31bc6152fb}',
8+
},
69
name: 'Code Medium',
710
website: 'https://github.com/Maluen/code-medium',
811
},
912

10-
auth: {
11-
clientId: '30d1a6209ed6f8d31760',
12-
clientSecret: '07ce4c1f2b9582b5e2470eb5189e7ea9084203e8',
13+
auths: {
14+
chrome: {
15+
clientId: '30d1a6209ed6f8d31760',
16+
clientSecret: '07ce4c1f2b9582b5e2470eb5189e7ea9084203e8',
17+
},
18+
19+
firefox: {
20+
clientId: '0c67dcc9e18d397ac74f',
21+
clientSecret: 'd1e2a02f20ec52a9609a80e83332e07a84b8b142',
22+
},
1323
},
1424
};

src/manifest.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var config = require('./common/config');
2+
13
module.exports = (browser, version) => ({
24
"key": (browser === 'chrome')
35
? "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhUUr0Z4y8DxD5WIezuYeGW3zDZkvGXST+uviv4jtXwkNVZI5XTUrs/pfYoYsOKdnrxkE47/mI+TiumUj7buB1pC+qeWYjVEshDD5Wum6J44RhXmAo7eb1e3u+IG0BmFvQOO+ENtRxIacZ/M8gexGRIlVWJKuRtcLREc7EkwxtWN58fPrWcYsuXfO3NDEkvrSz7hCCNgeVf/y0MKIz7ZRje8Afb1cRa2PtVAFJ2KUFikzghNFyAY8DVmXXZzrvUDbkeKxA/ja2+5TePhVhKBE+DpFGNUBhb1bEi+pl7ysssxFxjdwiW5/9q58JJeh1Mcu1lnoGIVQTspcd5fbioMNNQIDAQAB"
@@ -6,6 +8,7 @@ module.exports = (browser, version) => ({
68
minimum_chrome_version: (browser === 'chrome') ? "34" : undefined,
79
applications: (browser === 'firefox') ? {
810
"gecko": {
11+
"id": config.app.ids.firefox,
912
"strict_min_version": "50.0"
1013
}
1114
} : undefined,

0 commit comments

Comments
 (0)