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

Function getAuthToken

src/modules/gmail.js:263–283  ·  view source on GitHub ↗
(email, scopes = chrome.runtime.getManifest().oauth2.scopes, prompt)

Source from the content-addressed store, hash-verified

261}
262
263async function getAuthToken(email, scopes = chrome.runtime.getManifest().oauth2.scopes, prompt) {
264 const redirectURL = chrome.identity.getRedirectURL();
265 const state = getUUID();
266 const auth_params = {
267 client_id: CLIENT_ID,
268 include_granted_scopes: true,
269 login_hint: email,
270 redirect_uri: redirectURL,
271 response_type: 'token',
272 scope: scopes.join(' '),
273 state,
274 ...(prompt && {prompt})
275 };
276 const url = `${GOOGLE_API_HOST}/o/oauth2/v2/auth?${new URLSearchParams(Object.entries(auth_params))}`;
277 const responseURL = await chrome.identity.launchWebAuthFlow({url, interactive: true});
278 const search = new URLSearchParams(new URL(responseURL).hash.replace(/^#/, ''));
279 if (search.get('state') !== state) {
280 throw new Error('oauth2/v2/auth: wrong state parameter');
281 }
282 return search.get('access_token');
283}
284
285async function getAuthTokens(authCode) {
286 const url = 'https://oauth2.googleapis.com/token';

Callers 1

authorizeFunction · 0.85

Calls 2

getUUIDFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected