(email, legacyGsuite, scopes = chrome.runtime.getManifest().oauth2.scopes, {forcePicker = false} = {})
| 192 | } |
| 193 | |
| 194 | export async function authorize(email, legacyGsuite, scopes = chrome.runtime.getManifest().oauth2.scopes, {forcePicker = false} = {}) { |
| 195 | scopes = deDup([...GMAIL_SCOPES_DEFAULT, ...scopes]); |
| 196 | // incremental authorization to prevent checkboxes for the requested scopes on the consent screen |
| 197 | const access_token = await getAuthToken(email, GMAIL_SCOPES_DEFAULT, forcePicker ? 'select_account' : undefined); |
| 198 | const userInfo = await getUserInfo(access_token); |
| 199 | if (userInfo.email !== email) { |
| 200 | throw new MvError( |
| 201 | 'Email mismatch in user info from oauth2/v3/userinfo', |
| 202 | ERROR_GMAIL_ACCOUNT_MISMATCH, |
| 203 | {intendedEmail: email, actualEmail: userInfo.email} |
| 204 | ); |
| 205 | } |
| 206 | let auth = await getAuthCode(email, scopes); |
| 207 | if (!auth.code) { |
| 208 | throw new MvError('Authorization failed!', 'GOOGLE_OAUTH_ERROR'); |
| 209 | } |
| 210 | if (auth.prompt === 'none') { |
| 211 | // re-authorize with consent as without prompt the refresh token is empty |
| 212 | auth = await getAuthCode(email, scopes, 'consent'); |
| 213 | } |
| 214 | const tokens = await getAuthTokens(auth.code); |
| 215 | await storeAuthData(email, buildAuthMeta({...userInfo, ...tokens, legacyGsuite})); |
| 216 | return tokens.access_token; |
| 217 | } |
| 218 | |
| 219 | export async function unauthorize(email) { |
| 220 | const authMetaData = await mvelo.storage.get(GOOGLE_OAUTH_STORE); |
nothing calls this directly
no test coverage detected