java.io.IOException: Error reading credentials from stream, 'type' field not specified
Asked Answered
G

1

9

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?

Gillespie answered 23/5, 2020 at 15:34 Comment(0)
F
11

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).

Faceoff answered 10/9, 2020 at 13:7 Comment(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.Biomass
Where can I find type and what it is?Placet
I had the similar issue, and applying this solved it. I used the type: authorized_user and the set the three fields mentioned above.Bosporus

© 2022 - 2024 — McMap. All rights reserved.