-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathoauth2.js
More file actions
52 lines (47 loc) · 1.4 KB
/
Copy pathoauth2.js
File metadata and controls
52 lines (47 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* global LEETHUB_CLIENT_ID, LEETHUB_CLIENT_SECRET */
// eslint-disable-next-line no-unused-vars
const oAuth2 = {
/**
* Initialize
*/
init() {
this.KEY = 'leethub_token';
this.ACCESS_TOKEN_URL =
'https://github.com/login/oauth/access_token';
this.AUTHORIZATION_URL =
'https://github.com/login/oauth/authorize';
this.CLIENT_ID =
typeof LEETHUB_CLIENT_ID !== 'undefined'
? LEETHUB_CLIENT_ID
: 'SET_YOUR_CLIENT_ID';
this.CLIENT_SECRET =
typeof LEETHUB_CLIENT_SECRET !== 'undefined'
? LEETHUB_CLIENT_SECRET
: 'SET_YOUR_CLIENT_SECRET';
this.REDIRECT_URL = 'https://github.com/';
this.SCOPES = ['repo'];
},
/**
* Begin
*/
begin() {
this.init();
const state = crypto.getRandomValues(new Uint32Array(2)).join('');
chrome.storage.local.set({ leethub_oauth_state: state });
let url = `${this.AUTHORIZATION_URL}?client_id=${
this.CLIENT_ID
}&redirect_uri=${encodeURIComponent(this.REDIRECT_URL)}&scope=`;
for (let i = 0; i < this.SCOPES.length; i += 1) {
url += this.SCOPES[i];
}
url += `&state=${state}`;
chrome.storage.local.set({ pipe_leethub: true }, () => {
chrome.tabs.create({ url, active: true }, function () {
window.close();
chrome.tabs.getCurrent(function (tab) {
chrome.tabs.remove(tab.id, function () {});
});
});
});
},
};