title: How do I get a new Access Token before its expiration after user login with chrome.identity.launchWebAuthFlow?
body: <p>Sorry if this have been asked before but I've spend the whole day googling without any results.</p>
  
  <p>I'm using Chrome Identity API for a Chrome Extension I'm building for my work (interacting with Google Sheets API), and I'm looking to persist the login for the user but refresh tokens with this API are nowhere to be found.</p>
  
  <p>I first implemented <code>chrome.identity.getAuthToken()</code> and I was able to authorize the request to gSheets API, the problem came when the Access Token expired. I'm aware that calling <code>getAuthToken()</code> again refreshes the token if you call it with <code>interactive: false</code>, but only if the <a href="https://support.google.com/chrome/answer/2364824?hl=en&amp;co=GENIE.Platform%3DDesktop" rel="noreferrer">People</a> you're logged in with has the same email you authorized in the initial interaction with the popup, and this is not what I want simply because in my browser I'm logged with my personal email, and I want to authorize the work email for the extension. So, after 1 hour I need to request a new token which will prompt a login popup and this is a poor user experience.</p>
  
  <p>Then I tried with <code>chrome.identity.launchWebAuthFlow()</code> with the endpoint <a href="https://accounts.google.com/o/oauth2/v2/auth" rel="noreferrer">https://accounts.google.com/o/oauth2/v2/auth</a> knowing that <code>launchWebAuthFlow()</code> is for non-Google accounts, and even though it worked well, as far as I know, there is no way to refresh the token after — let's say — 45 minutes to avoid kicking out the user.</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    switch (request.type) {
      case "login":
        let authURL = "https://accounts.google.com/o/oauth2/v2/auth";
        const clientId = `&lt;CLIENT_ID&gt;`;
        const redirectURL = chrome.identity.getRedirectURL("oauth2");
        const auth_params = {
          client_id: clientId,
          redirect_uri: redirectURL,
          response_type: "token",
          scope: "https://www.googleapis.com/auth/spreadsheets"
        };
  
        const paramString = Object.keys(auth_params)
          .map(function(k) {
            return k + "=" + auth_params[k];
          })
          .join("&amp;");
  
        authURL += "?" + paramString;
  
        chrome.identity.launchWebAuthFlow(
          { url: authURL, interactive: true },
          function(responseURL) {
            if (chrome.runtime.lastError) {
              console.log(chrome.runtime.lastError);
              return;
            }
  
            if (responseURL) {
              const paramsString = responseURL.substring(
                responseURL.indexOf("#") + 1
              );
              const params = new URLSearchParams(paramsString);
  
              const paramsObj = () =&gt; {
                const obj = {};
                for (var entry of params.entries()) {
                  obj[entry[0]] = entry[1];
                }
                return obj;
              };
  
              const { access_token } = paramsObj();
  
              sendResponse({
                access_token
              });
            } else {
              console.log(`${responseURL} defined?`);
            }
          }
        );
  
        return true;
      default:
        console.log("placeholder");
        break;
        }
  });
  </code></pre>
  
  <p>I'm willing to ditch Chrome Identity API and use another OAuth2 flow if it means I can improve the user experience for the user.</p>
  
  <p>TL;DR: I want to get a new access token either with Chrome Identity API or any other OAuth2 implementation a few minutes before the previous token expires, while being able to use a Google Account different than the logged in Chrome (People).</p>