Skip to content

Commit 1c1016f

Browse files
committed
fix: make github enterprise OAuth work by requesting the host permission for the instance
1 parent bbbc98b commit 1c1016f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
"storage",
4646
"https://github.com/login/oauth/access_token"
4747
],
48+
"optional_permissions": [
49+
"https://*/*"
50+
],
4851
"version": "1.3.4",
4952
"icons": {
5053
"48": "images/icon-48.png",

scripts/options.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@ class AccountManager extends window.StorageManager {
148148
else {
149149
details = this.getDetails(type);
150150
}
151+
152+
if(type === 'enterprise') {
153+
if(!details.instanceURL.startsWith('https:')) {
154+
this.showError("Instance must be reachable via HTTPS for OAuth");
155+
return;
156+
}
157+
let permissionURL = details.instanceURL;
158+
if(!permissionURL.endsWith('/')) {
159+
permissionURL += '/';
160+
}
161+
permissionURL += 'login/oauth/access_token';
162+
const granted = await browser.permissions.request({
163+
origins: [ permissionURL ]
164+
});
165+
if(!granted) {
166+
this.showError("Can not OAuth without host permission for Enterprise instance");
167+
return;
168+
}
169+
}
151170
browser.runtime.sendMessage({
152171
topic: "login",
153172
type,
@@ -239,7 +258,7 @@ class AccountManager extends window.StorageManager {
239258
optgroup.label = instanceConfig.instanceURL;
240259
optgroup.id = 'enterprise-preconfigured';
241260
const option = new Option(browser.i18n.getMessage('account_enterprise-preconfig', instanceConfig.instanceURL), 'enterprise-preconfig', true, true);
242-
optgroup.appned(option);
261+
optgroup.append(option);
243262
this.form.querySelector("select").append(optgroup);
244263
}
245264
}

0 commit comments

Comments
 (0)