MCPcopy Create free account
hub / github.com/mailvelope/mailvelope / authorize

Function authorize

src/modules/gmail.js:194–217  ·  view source on GitHub ↗
(email, legacyGsuite, scopes = chrome.runtime.getManifest().oauth2.scopes, {forcePicker = false} = {})

Source from the content-addressed store, hash-verified

192}
193
194export 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
219export async function unauthorize(email) {
220 const authMetaData = await mvelo.storage.get(GOOGLE_OAUTH_STORE);

Callers

nothing calls this directly

Calls 7

deDupFunction · 0.90
getAuthTokenFunction · 0.85
getAuthCodeFunction · 0.85
getAuthTokensFunction · 0.85
storeAuthDataFunction · 0.85
buildAuthMetaFunction · 0.85
getUserInfoFunction · 0.70

Tested by

no test coverage detected