title: Error Response while getting jwt access token for google user with Google Credential Object
body: <p>I am trying to get the jwt access tokens for each user of my gsuite domain using the GoogleCredential and JacksonFactory libraries. </p>
  
  <p>Code sample - </p>
  
  <pre><code>GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
                  .setJsonFactory(JSON_FACTORY)
                  .setServiceAccountId(clientEmail)
                  .setServiceAccountScopes(scopes)
                  .setServiceAccountPrivateKeyFromP12File(privateKeyFile)
                  .setServiceAccountUser(userEmail)
                  .build();
  
              credential.refreshToken();
              String accessToken = credential.getAccessToken();
  </code></pre>
  
  <p>All fields - clientEmail, scopes, key and userEmail are neither null nor empty</p>
  
  <p>For a few number of users I am not able to get the access token and am getting this error</p>
  
  <pre><code>com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191) com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127) com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:96) com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85) com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81) com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88) com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287) com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:269) com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) com.hubble.hubbleEngine.policyTypes.OAuth.getJWTAccessToken(OAuth.java:815)
  </code></pre>
  
  <p>This is happening only the first time, I am trying to get the access tokens. When I try to get the access tokens again for all users, I am able to get the access tokens for the users which were throwing the error the first time.</p>
  
  <p>I debugged a bit and saw that the error gets generated from the following function present in com.google.api.client.auth.oauth2.TokenRequest</p>
  
  <pre><code>public final HttpResponse executeUnparsed() throws IOException {
  // must set clientAuthentication as last execute interceptor in case it needs to sign request
  HttpRequestFactory requestFactory =
      transport.createRequestFactory(new HttpRequestInitializer() {
  
        public void initialize(HttpRequest request) throws IOException {
          if (requestInitializer != null) {
            requestInitializer.initialize(request);
          }
          final HttpExecuteInterceptor interceptor = request.getInterceptor();
          request.setInterceptor(new HttpExecuteInterceptor() {
            public void intercept(HttpRequest request) throws IOException {
              if (interceptor != null) {
                interceptor.intercept(request);
              }
              if (clientAuthentication != null) {
                clientAuthentication.intercept(request);
              }
            }
          });
        }
      });
  // make request
  HttpRequest request =
      requestFactory.buildPostRequest(tokenServerUrl, new UrlEncodedContent(this));
  request.setParser(new JsonObjectParser(jsonFactory));
  request.setThrowExceptionOnExecuteError(false);
  HttpResponse response = request.execute();
  if (response.isSuccessStatusCode()) {
    return response;
  }
  throw TokenResponseException.from(jsonFactory, response);
  </code></pre>
  
  <p>}</p>
  
  <p>The request.execute() hits the "<a href="https://accounts.google.com/o/oauth2/token" rel="nofollow noreferrer">https://accounts.google.com/o/oauth2/token</a>" to get the token but it is throwing some error response. Due to this it throws the TokenResponseException mentioned at last. Here, the response.getContent() is null due to which the whole null exception is occuring. </p>
  
  <p>Is there a way to know, which kind of error response is thrown by the call. (>300 or &lt;200)? Or why such a case is happening ?</p>