7

I am trying to authenticate a java app into the google photos api, using my own account, which doesn't support service_account as per documentation. The problem is that the file generated by the google-console for OAuth2 authentication doesn't contain a type field, that only the file generated by creating credentials for a service account will work.

I tried authenticating the web-app through gcloud auth application-default login with/without reading the generated file, which does contain a type/client_id/client_secret/refresh_token.

E.G.:

        PhotosLibrarySettings settings =
                PhotosLibrarySettings.newBuilder()
                        .setCredentialsProvider(FixedCredentialsProvider.create(
                                GoogleCredentials.fromStream(
                                        new FileInputStream("credentials.json")
                                )))
                        .build();

Any ideas that might help?

Stela
  • 71
  • 1
  • 1
  • 2

1 Answers1

10

I had the same issue when trying to use Google API for Calendar. As explained here, your json file is invalid. He explains how to generate the correct json, using the "Service Account key" credential.

I don't know if this solves your problem, but it didn't for me. This type of credential requires a G Suit account, which wasn't what I was looking for. I was using the GoogleCredentials for OAuth2 authentication and in my json file, the only things it requires is type, client_id, client_secret and refresh_token.

The type accepts "service_account" (for G Suit) and "authorized_user" (for OAuth2).

Caio Vincenzo
  • 101
  • 1
  • 4
  • 3
    Had the same issue, and followed the solution flow mentioned by Caio. If you check the SA key downloaded, it does have a type entry. Once that was added, the authentication worked without a glitch. – RaptorX Sep 03 '21 at 11:41
  • Where can I find type and what it is? – Drishti Jain Nov 08 '22 at 05:24