| 283 | } |
| 284 | |
| 285 | async function getAuthTokens(authCode) { |
| 286 | const url = 'https://oauth2.googleapis.com/token'; |
| 287 | const params = { |
| 288 | client_id: CLIENT_ID, |
| 289 | code: authCode, |
| 290 | client_secret: CLIENT_SECRET, |
| 291 | grant_type: 'authorization_code', |
| 292 | redirect_uri: chrome.identity.getRedirectURL() |
| 293 | }; |
| 294 | const result = await fetch(url, { |
| 295 | method: 'POST', |
| 296 | body: new URLSearchParams(Object.entries(params)).toString(), |
| 297 | mode: 'cors', |
| 298 | headers: { |
| 299 | 'Content-Type': 'application/x-www-form-urlencoded' |
| 300 | } |
| 301 | }); |
| 302 | return result.json(); |
| 303 | } |
| 304 | |
| 305 | async function getRefreshedAccessToken(refresh_token) { |
| 306 | const url = 'https://oauth2.googleapis.com/token'; |