title: Google+ Sign-In for server-side apps auth not working
body: <p>I trying to add Google+ auth for wordpress site.
  What I want: after auth in Google+ if user not registered on site - I redirect him to page where he enters his username; if user already registered - it will be logged in.
  here my js code:</p>
  
  <pre><code>function doGooglePlusLogin(authResult) {
      if (authResult['code']) {
          jQuery('#signinButton').attr('style', 'display: none');
          jQuery.ajax({
              url: '&lt;?php echo site_url(); ?&gt;/wp-admin/admin-ajax.php',
              type: 'get',
              dataType: 'json',
              data: {
                  action: 'login_gplus',
                  code: authResult['code']
              },
              success: function(result) {
              },
          });
      } else if (authResult['error']) {
      }
  }
  </code></pre>
  
  <p>here my php code:</p>
  
  <pre><code>function login_gplus() {
  $response = array();
  
  if (isset($_GET['code']) &amp;&amp; !empty($_GET['code'])) {
      @session_start();
      $client = new Google_Client();
      $client-&gt;setApplicationName('Test');
      $client-&gt;setAccessType('offline');
      $client-&gt;setClientId(get_option(SOCIAL_GPLUS_CLIENT_ID));
      $client-&gt;setClientSecret(get_option(SOCIAL_GPLUS_CLIENT_SECRET));
      $client-&gt;setDeveloperKey(get_option(SOCIAL_GPLUS_API_KEY));
      $client-&gt;setRedirectUri(get_option(SOCIAL_GPLUS_REDIRECT_URIS));
      $client-&gt;setApprovalPrompt('auto');
  
      $code = $_GET['code'];
      $client-&gt;authenticate($code);
  
      $token = json_decode($client-&gt;getAccessToken());
      $reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . $token-&gt;access_token;
      $req = new Google_HttpRequest($reqUrl);
  
      $tokenInfo = json_decode(
              $client-&gt;getIo()
                      -&gt;authenticatedRequest($req)
                      -&gt;getResponseBody());
  
      if ($tokenInfo-&gt;error) {
          $response['test'] = $tokenInfo-&gt;error;
          send_json_response($response);
          die();
      }
      if ($tokenInfo-&gt;audience != get_option(SOCIAL_GPLUS_CLIENT_ID)) {
          $response['test'] = "Token's client ID does not match app's.";
          send_json_response($response);
          die();
      }
      $response['test'] = 'Succesfully connected with token: ' . print_r($token, true);
  }
  send_json_response($response);
  die();
  }
  </code></pre>
  
  <p>User successfully authorized in Google+ but in php I got this:</p>
  
  <p>Fatal error: Uncaught exception 'Google_AuthException' with message 'Error fetching OAuth2 access token, message: 'redirect_uri_mismatch'' in /var/www/html/v4/wp-content/plugins/social/google-plus/google-api/auth/Google_OAuth2.php:113Stack trace:#0 /var/www/html/v4/wp-content/plugins/social/google-plus/google-api/Google_Client.php(131): Google_OAuth2->authenticate(Array, '4/ScmpTqEIWt0SJ...')#1 /var/www/html/v4/wp-content/plugins/social/google-plus/functions.php(35): Google_Client->authenticate('4/ScmpTqEIWt0SJ...')#2 [internal function]: login_gplus('')#3 /var/www/html/v4/wp-includes/plugin.php(406): call_user_func_array('login_gplus', Array)#4 /var/www/html/v4/wp-admin/admin-ajax.php(74): do_action('wp_ajax_nopriv_...')#5 {main} thrown in /var/www/html/v4/wp-content/plugins/social/google-plus/google-api/auth/Google_OAuth2.php on line 113</p>
  
  <p>In App Settings Redirect URIs specified as <a href="http://example.com/wp-admin/admin-ajax.php" rel="noreferrer">http://example.com/wp-admin/admin-ajax.php</a>.
  What do I do wrong?</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Google+ Sign-In button definition:</p>
  
  <pre><code>&lt;span id="signinButton"&gt;
    &lt;span class="g-signin"
     data-callback="doGooglePlusLogin"
     data-clientid="&lt;?php echo $this-&gt;gplus_client_id; ?&gt;"
     data-cookiepolicy="single_host_origin" data-accesstype="offline"
     data-requestvisibleactions="http://schemas.google.com/AddActivity"
     data-scope="https://www.googleapis.com/auth/plus.login"&gt;
    &lt;/span&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>SOCIAL_GPLUS_REDIRECT_URIS is <code>example.com/wp-admin/admin-ajax.php?action=login_gplus</code></p>