UNPKG

insomnia-plugin-valorant

Version:
47 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkWebViewData = void 0; const parse_auth_redirect_1 = require("./parse-auth-redirect"); /** * Checks if the webview partition has valid login data * If so, the promise resolves with the access token and expiration time * If not, the promise rejects with an error message */ async function checkWebViewData() { return new Promise(async (resolve, reject) => { const valRefreshWebView = document.createElement('webview'); valRefreshWebView.style.display = 'none'; valRefreshWebView.nodeintegration = false; // Set partition to avoid Insomnia stripping out the Origin headers needed for CORS valRefreshWebView.partition = 'persist:valorant'; const checkForToken = async (event) => { if (event.url.startsWith('https://playvalorant.com/') && event.url.includes('access_token')) { cleanupWebView(); try { resolve((0, parse_auth_redirect_1.parseAuthRedirect)(event.url)); } catch (e) { reject(e); } } else if (event.url.startsWith('https://authenticate.riotgames.com/')) { cleanupWebView(); reject('No login data found or login data expired'); } }; const cleanupWebView = () => { valRefreshWebView.removeEventListener('did-navigate', checkForToken); // Ignore errors relating to the webview not being attached to the dom try { valRefreshWebView.stop(); } catch (ignored) { } document.body.removeChild(valRefreshWebView); }; valRefreshWebView.addEventListener('did-navigate', checkForToken); valRefreshWebView.src = 'https://auth.riotgames.com/authorize?redirect_uri=https%3A%2F%2Fplayvalorant.com%2Fopt_in%2F&client_id=play-valorant-web-prod&response_type=token%20id_token&nonce=1&scope=account%20openid'; document.body.appendChild(valRefreshWebView); }); } exports.checkWebViewData = checkWebViewData; //# sourceMappingURL=check-webview-data.js.map