title: Login using Google in Chrome Extension
body: <p>I used this below code to create login using google </p>
  
  <p><strong>background.js</strong></p>
  
  <pre><code>var manifest = chrome.runtime.getManifest();
  
          var clientId = encodeURIComponent(manifest.oauth2.client_id);
          var scopes = encodeURIComponent(manifest.oauth2.scopes.join(' '));
          var redirectUri = encodeURIComponent('urn:ietf:wg:oauth:2.0:oob:auto');
  
          var url = 'https://accounts.google.com/o/oauth2/auth' + 
                    '?client_id=' + clientId + 
                    '&amp;response_type=id_token' + 
                    '&amp;access_type=offline' + 
                    '&amp;redirect_uri=' + redirectUri + 
                    '&amp;scope=' + scopes;
  
          var RESULT_PREFIX = ['Success', 'Denied', 'Error'];
          chrome.tabs.create({'url': 'about:blank'}, function(authenticationTab) {
              chrome.tabs.onUpdated.addListener(function googleAuthorizationHook(tabId, changeInfo, tab) {
                  if (tabId === authenticationTab.id) {
                      var titleParts = tab.title.split(' ', 2);
  
                      var result = titleParts[0];
                      if (titleParts.length == 2 &amp;&amp; RESULT_PREFIX.indexOf(result) &gt;= 0) {
                          chrome.tabs.onUpdated.removeListener(googleAuthorizationHook);
                          chrome.tabs.remove(tabId);
  
                          var response = titleParts[1];
                          switch (result) {
                              case 'Success':
                                  // Example: id_token=&lt;YOUR_BELOVED_ID_TOKEN&gt;&amp;authuser=0&amp;hd=&lt;SOME.DOMAIN.PL&gt;&amp;session_state=&lt;SESSION_SATE&gt;&amp;prompt=&lt;PROMPT&gt;
                                  console.log("suc:"+response);
                              break;
                              case 'Denied':
                                  // Example: error_subtype=access_denied&amp;error=immediate_failed
                                  console.log("denied:"+response);
                              break;
                              case 'Error':
                                  // Example: 400 (OAuth2 Error)!!1
                                  console.log("error:"+response);
                              break;
                          }
                      }
                  }
              });
  
              chrome.tabs.update(authenticationTab.id, {'url': url});
  </code></pre>
  
  <p>I got this on background console</p>
  
  <pre><code>error:id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc2ZjVhMjk0MWUyZjI0YjBlYzYwZjdmMjE2MWE0MDc1YWM3YzAzNjkifQ.eyJhenAiOiIxNjE5ODU4ODI5NDgtc2FxMDk1dGtpZzBsZ3Bic281dGVnYmd1MTFuNzJuc2guYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIxNjE5ODU4ODI5NDgtc2FxMDk1dGtpZzBsZ3Bic281dGVnYmd1MTFuNzJuc2guYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTU1MjM0ODc5OTQ3NDkyNzg1NjUiLCJlbWFpbCI6Imt1c2hhbC5qYWluNjNAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6ImFjY291bnRzLmdvb2dsZS5jb20iLCJpYXQiOjE0OTkzNjEzNzEsImV4cCI6MTQ5OTM2NDk3MX0.aBTW7AqRlsnrR9HZhSAid9oU87q0FgcdXqbFpA5PfHQB1s8Cy9GpCYk0Gergom4ZODOG6mDWC2x6DX9sVas6e7b9EhhMeckafhVP5QcdSilK9TcHOfGBYDfw_Jktcf2EIjFAuFirkTyyLiFsXG657jU29k4_Yf7bhPehk8jcj1Jk8Kg-a6vnIO-X6zSc9FXoNUxLjg_KaCcLVa6fR4HqwuzYLKte1ZEzL4S3lsA8TGKsEdpzp15dkCT82w26O6GolA2vpufQ1caKp7zFSC80z0J5Sk2BkBgcTm8PF29TDEv72ImMCYsmqK9rYTd2LCFTizVs_LkE8S3RQ66XvMJHfw&amp;authuser=0&amp;session_state=ecc7aeb026120aac5fc8a18fd1e875b32dc8a52e..e1b4&amp;prompt=consent
  </code></pre>
  
  <p>Here is the screenshot of console which is the result of console.log(tab.title)</p>
  
  <p><a href="https://i.stack.imgur.com/M8Yy8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M8Yy8.png" alt="enter image description here"></a></p>
  
  <p>Every time Error switch case is run because tab.title value has Error, but it gives id_token value. So, I need to know why error occurred ?</p>
  
  <p>Is there something missing in this code or wrong ?</p>
  
  <p>And also need to know if I got the success (after your answer) then what to do next to get the user data like email_id and other details.</p>