Error reading credentials from stream, 'type' field not specified.

See original GitHub issue

Environment details

  1. Create Web application credentials (web server app)
  2. OS type and version: macOS 10.15.6
  3. Java version: java8
  4. google-auth-library version(s): 1.3.0

Steps to reproduce

this is my json file :

{
  "web": {
    "client_id": "xxxxx-xxxxx.apps.googleusercontent.com",
    "project_id": "xxxxx-xxxxx-xxxx",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxxxx-xxxxx",
    "redirect_uris": ["http://localhost:8888/Callback"]
  }
}

Code example

GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream("/path/to/credentials.json"));
credentials.refreshIfExpired();
AccessToken token = credentials.getAccessToken();
// OR
AccessToken token = credentials.refreshAccessToken();

Stack trace

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

	at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:166)
	at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:139)

how to solve this problem?

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sericalcommented, Nov 19, 2021

Yes I read this code before I opened issues

but the json file obtained through this tutorial Create Web application credentials (web server app) does not have a type attribute.

It’s exactly the same as below. I didn’t modify any information except sensitive information.

{
  "web": {
    "client_id": "xxxxx-xxxxx.apps.googleusercontent.com",
    "project_id": "xxxxx-xxxxx-xxxx",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxxxx-xxxxx",
    "redirect_uris": ["http://localhost:8888/Callback"]
  }
}

so I don’t know how to do it

0reactions
TimurSadykovcommented, Jul 8, 2022

Thanks @Sita04

closing since a solution was provided

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.io.IOException: Error reading credentials from stream ...
The problem is that the file generated by the google-console for OAuth2 authentication doesn't contain a type field, that only the file ...
Read more >
Error reading credentials from stream · Issue #141 - GitHub
Hi! I'm having this error: java.io.IOException: Error reading credentials from stream, 'type' field not specified.
Read more >
com.google.auth.oauth2.UserCredentials.fromJson java code ...
Returns credentials defined by a JSON file stream using the format ... new IOException("Error reading credentials from stream, 'type' field not specified.
Read more >
com.google.api.client.googleapis.auth.oauth2 ... - Java2s.com
Here is the source code for com.google.api.client.googleapis.auth.oauth2. ... throw new IOException("Error reading credentials from stream, 'type' field not ...
Read more >
[NIFI] - GCPCredentialsControllerService - ListGCS... - 195519
[NIFI] - GCPCredentialsControllerService - ListGCSBucket ... lOException: Error reading credentials from stream, 'type' field not specified ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found