Redirect_URI error when using GoogleAuth.grantOfflineAccess to authenticate on server : <p>I'm trying to use the authorization flow outlined at <a href="https://developers.google.com/identity/sign-in/web/server-side-flow" rel="noreferrer">https://developers.google.com/identity/sign-in/web/server-side-flow</a>.
I've created the credentials as indicated... with no Authorized redirect URIs specified as the doc indicates: "The Authorized redirect URI field does not require a value. Redirect URIs are not used with JavaScript APIs."</p>

<p>The code initiating the authorization is:
Client button and callback:</p>

<pre><code>&lt;script&gt;
$('#signinButton').click(function() {


    var auth2 = gapi.auth2.getAuthInstance(); 
    auth2.grantOfflineAccess().then(signInCallback);

});
function signInCallback(authResult) {

    console.log('sending to server');

    if (authResult['code']) {

        // Send the code to the server
        $.ajax({
          type: 'POST',
          url: 'CheckAuth',

          headers: {
            'X-Requested-With': 'XMLHttpRequest'
          },
          contentType: 'application/octet-stream; charset=utf-8',
          success: function(result) {
            // Handle or verify the server response.
          },
          processData: false,
          data: authResult['code']
        });
      } else {
        // There was an error.
      }
}
&lt;/script&gt;
</code></pre>

<p>Server side (CheckAuth method to create credentials from auth code, which it receives correctly via the javascript callback):</p>

<pre><code>private Credential authorize() throws Exception {
    // load client secrets
    InputStream is = new FileInputStream(clientSecretsPath_);
    InputStreamReader isr = new InputStreamReader(is);
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, isr);



    String redirect_URI = "";
    GoogleTokenResponse tokenResponse =
                  new GoogleAuthorizationCodeTokenRequest(
                          httpTransport, JSON_FACTORY,
                      "https://www.googleapis.com/oauth2/v4/token",
                      clientSecrets.getDetails().getClientId(),
                      clientSecrets.getDetails().getClientSecret(),
                      token_,
                      redirect_URI)  
                      .execute();

        String accessToken = tokenResponse.getAccessToken();

        // Use access token to call API
        GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
        return credential;

    }
</code></pre>

<p>The flow works correctly, up until the point my server attempts to exchange the authorization code for the token response (GoogleAuthorizationCodeTokenRequest.execute() )... the auth server returns: </p>

<pre><code>400 Bad Request
{
  "error" : "invalid_request",
  "error_description" : "Missing parameter: redirect_uri"
}
</code></pre>

<p>Given the error, I looked in debug at the auth instance in javascript and noted what it indicated was the redirect_uri. I then updated my google credentials and specified that URI in the Authorized redirect URIs (it's the URL that accessed the javascript, as the auth server correctly returns to the specified javascript callback). With the updated credentials and the URI specified in the instantiation of GoogleAuthorizationCodeTokenRequest (String redirect_URI = "<a href="http://example.com:8080/JavascriptLocation" rel="noreferrer">http://example.com:8080/JavascriptLocation</a>";), the error then becomes:</p>

<pre><code>400 Bad Request
{ 
  "error" : "redirect_uri_mismatch",
  "error_description" : "Bad Request"
}
</code></pre>

<p>I've tracked all the way through to the actual HttpRequest to the auth server (www.googleapis.com/oauth2/v4/token) and cannot tell what redirect_uri it is looking for.</p>

<p>Does anyone know what the value of redirect_uri should be in this case (when using grantOfflineAccess())? I'm happy to post more of the code, if that is at all helpful... just didn't want to flood the page. Thanks. </p>
