| 233 | } |
| 234 | |
| 235 | async function getAuthCode(email, scopes = chrome.runtime.getManifest().oauth2.scopes, prompt) { |
| 236 | const redirectURL = chrome.identity.getRedirectURL(); |
| 237 | const state = getUUID(); |
| 238 | const auth_params = { |
| 239 | access_type: 'offline', |
| 240 | client_id: CLIENT_ID, |
| 241 | include_granted_scopes: true, |
| 242 | login_hint: email, |
| 243 | redirect_uri: redirectURL, |
| 244 | response_type: 'code', |
| 245 | scope: scopes.join(' '), |
| 246 | state |
| 247 | }; |
| 248 | if (prompt) { |
| 249 | auth_params.prompt = prompt; |
| 250 | } |
| 251 | const url = `${GOOGLE_API_HOST}/o/oauth2/v2/auth?${new URLSearchParams(Object.entries(auth_params))}`; |
| 252 | const responseURL = await chrome.identity.launchWebAuthFlow({url, interactive: true}); |
| 253 | const search = new URL(responseURL).searchParams; |
| 254 | if (search.get('state') !== state) { |
| 255 | throw new Error('oauth2/v2/auth: wrong state parameter'); |
| 256 | } |
| 257 | return { |
| 258 | code: search.get('code'), |
| 259 | prompt: search.get('prompt') |
| 260 | }; |
| 261 | } |
| 262 | |
| 263 | async function getAuthToken(email, scopes = chrome.runtime.getManifest().oauth2.scopes, prompt) { |
| 264 | const redirectURL = chrome.identity.getRedirectURL(); |