-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (36 loc) · 963 Bytes
/
background.js
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
async function getToken(data) {
const body = JSON.stringify({
scope: 'mobile',
grant_type: 'password',
siteId: 'au',
client_id: data.clientId,
username: data.username,
password: data.password,
});
const res = await fetch(`https://au.jora.com/oauth/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'JoraSupra/1',
},
body,
});
return res.json();
}
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
switch (message.type) {
case 'getToken':
(async () => {
const { credentials } = await chrome.storage.local.get('credentials');
console.log(credentials);
const token = await getToken({
clientId: credentials.clientId,
username: credentials.username,
password: credentials.password,
});
sendResponse(token);
})();
break;
}
return true;
});