title: How to create a login using google in chrome extension
body: <p>I just recently building an plugin in which I need to integrate Google Login. I searched and found <code>chrome.identity</code> to authenticate user using google account but that does not work well.</p>
  <p>So I came across a solution by using this code below</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/v2/auth' + 
                '?client_id=' + clientId + 
                '&amp;response_type=code' + 
                '&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(&quot;suc:&quot;+response);
                          break;
                          case 'Denied':
                              // Example: error_subtype=access_denied&amp;error=immediate_failed
                              console.log(&quot;denied:&quot;+response);
                          break;
                          case 'Error':
                              // Example: 400 (OAuth2 Error)!!1
                              console.log(&quot;error:&quot;+response);
                          break;
                      }
                  }
              }
          });
  
          chrome.tabs.update(authenticationTab.id, {'url': url});
      });
  </code></pre>
  <p>In which if I remove <code>v2</code> from the url variable then it always gives error in the turn with <code>id_token</code> but if I add <code>v2</code> then its success and return code.</p>
  <p>So now I read google documentation which said that now create a post request using <code>client_id and client_secret</code> but I chrome app create credential on google console which does not have <code>client_secret</code></p>
  <p>Now what should I do ? Is there anything that I missed or do wrong here and I also came across one of the chrome extension <code>Screencastify</code> use google login.</p>
  <p>Can anyone explain how they do it ?</p>