title: GCP: "Invalid JWT Signature" when using Service Account JSON
body: <p>I'm using Google's gRPC library to access data from my GCP domain.
  My code performs authentication using a service account JSON key.
  It worked fine for about a month, until recently I started receiving the following error on any action I try to perform:</p>
  <pre><code>{&quot;error&quot;:&quot;invalid_grant&quot;,&quot;error_description&quot;:&quot;Invalid JWT Signature.&quot;}
  </code></pre>
  <p>I should note that the authentication process executes without errors, as does creation of the service object (see Java code example below). The error is thrown when I try to perform any data access action, e.g. the listSecrets method in the example below.</p>
  <p>Searching for this problem on the web, I have found mainly answers that point to a system time/timezone error; however, the date &amp; time &amp; timezone on my computer are completely accurate.
  Any suggestions?</p>
  <p>Example of my Java code:</p>
  <pre><code>String projectId = &quot;my-project&quot;;
  GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(&quot;C:\\Users\\elisha.l\\Downloads\\co-club-project-01-3588a3330456.json&quot;));
  SecretManagerServiceClient client = SecretManagerServiceClient.create();
  ProjectName parent = ProjectName.of(projectId);
  ListSecretsPagedResponse response = client.listSecrets(parent);
  </code></pre>
  <p>Stacktrace of the error:</p>
  <pre><code>Exception in thread &quot;main&quot; com.google.api.gax.rpc.UnavailableException: io.grpc.StatusRuntimeException: UNAVAILABLE: Credentials failed to obtain metadata
      at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:69)
      at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
      at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
      at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
      at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
      at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1050)
      at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
      at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1176)
      at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:969)
      at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:760)
      at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:563)
      at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:533)
      at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:434)
      at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)
      at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:763)
      at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:742)
      at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
      at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed
          at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57)
          at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
          at com.google.cloud.secretmanager.v1.SecretManagerServiceClient.listSecrets(SecretManagerServiceClient.java:245)
          at com.google.cloud.secretmanager.v1.SecretManagerServiceClient.listSecrets(SecretManagerServiceClient.java:196)
          at google.Secret.main(Secret.java:26)
  Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE: Credentials failed to obtain metadata
      at io.grpc.Status.asRuntimeException(Status.java:533)
      ... 14 more
  Caused by: java.io.IOException: Error getting access token for service account: 400 Bad Request
  POST https://oauth2.googleapis.com/token
  {&quot;error&quot;:&quot;invalid_grant&quot;,&quot;error_description&quot;:&quot;Invalid JWT Signature.&quot;}
      at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:444)
      at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:157)
      at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:145)
      at com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadata(ServiceAccountCredentials.java:603)
      at com.google.auth.Credentials.blockingGetToCallback(Credentials.java:112)
      at com.google.auth.Credentials$1.run(Credentials.java:98)
      ... 7 more
  Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
  POST https://oauth2.googleapis.com/token
  {&quot;error&quot;:&quot;invalid_grant&quot;,&quot;error_description&quot;:&quot;Invalid JWT Signature.&quot;}
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1113)
      at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:441)
      ... 12 more
  </code></pre>