Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Trouble with GoogleCredentials on Server

Hey everyone! I’m facing an issue where my GoogleCredentials work perfectly fine on my local machine but don’t on the server. I’m using the following code:

InputStream credentialsStream = createJsonFile(keyFileStream);
GoogleCredentials credentials = GoogleCredentials.fromStream(credentialsStream)
.createScoped(
Collections.singletonList("https://www.googleapis.com/auth/devstorage.full_control")
);

Problem:

  • It works locally, but on the server, not working and I'm not getting any error it stuck on this step.

Anyone else faced this issue or have any solutions?

0 1 180
1 REPLY 1

Hi @devmanish,

You are using GoogleCredentials successfully on your local machine, but it doesn't work on the server and the code snippet you provided seems to be functioning correctly on the local machine. Also I’ve taken note that you're not getting an error or a credentials object on the server.

Here are the potential causes and solutions that might help with your concern:

  • Incorrect Credentials File:
    • Double-check that the credentials file you're using on the server is identical to the one on your local machine.
    • Make sure it has the appropriate permissions for the service account or user running the application on the server.
  • Missing Environment Variables:
    • If your credentials rely on environment variables (e.g., GOOGLE_APPLICATION_CREDENTIALS), verify that they're set correctly on the server.
    • You might need to set them manually in your server's environment or use a configuration management tool.
  • Network Connectivity Issues:
    • Make sure the server has internet access to reach Google's authentication servers.
    • Check for firewalls or proxies that might be blocking communication.
  • Service Account Permissions:
    • If you're using a service account, confirm that it has the necessary permissions to access the Google Cloud Storage API.
    • You can grant permissions through the Google Cloud Console or the Cloud IAM API.
  • Incorrect Scopes:
    • The scopes you're providing seem correct for full control over Google Cloud Storage, but double-check the documentation for the specific API you're using.
    • Ensure they're listed correctly in your code.

If the workarounds above don't work, you can contact Google Cloud Support for a more in-depth analysis. When contacting them, please provide comprehensive details and include screenshots. This will help them better understand and address your issue.

I hope the above information is helpful.