question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to create Service Account from JSON

See original GitHub issue

This is my code:

const string serviceAccountEmail = "...";
string[] scopes = { CalendarService.Scope.CalendarReadonly };
Stream stream = new FileStream(@"C:\...\console-generated-key.json", FileMode.Open, FileAccess.Read, FileShare.Read);
var credential = GoogleCredential.FromStream(stream);
credential.CreateScoped(scopes);
var service = new CalendarService(new BaseClientService.Initializer
{
     HttpClientInitializer = credential,
     ApplicationName = "My Application"
});
var request = service.Events.List("my-calendar@resource.calendar.google.com");
var events = request.Execute();

I get the following JSON back from googleapis.com:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}

I’m able to authenticate with a .p12 for the same service account using:

ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
     Scopes = scopes,
}.FromCertificate(certificate));

Related: #533

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jskeetcommented, Jun 15, 2023

@miguelRedit: Given that this issue is over 7 years old, I think it would be more productive to create a new issue with more details.

1reaction
jskeetcommented, Jun 15, 2023

@miguelRedit: Again, please create a new issue rather than continuing to add things here. But I strongly suspect you’re not actually loading the JSON file you think you are… because assuming the type here is "service_account" you wouldn’t get that error. In the new issue, please provide a complete example with a sample file - obviously not containing your actual credentials, but with all IDs/keys replaced by “xxx”.

The error message you’re showing would happen if you had a JSON file which didn’t specify type at all. (The empty string before the period at the end is the type…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create and delete service account keys | IAM Documentation
How to create and delete service account keys.
Read more >
GCP - Service Account key - JSON download fails
Went to IAM & Admin -> Created a new service account -> created a key -> JSON -> The problem still persists. Use...
Read more >
Create service accounts | IAM Documentation
This page explains how to create service accounts using the Identity and Access Management (IAM) API, the Google Cloud console, and the gcloud...
Read more >
Create a service account - Google Workspace Admin Help
Create new key.​​ Make sure the key type is set to JSON and click Create. You'll get a message that the service account's...
Read more >
Google Service Account Json Problems - Builds
I'm trying to upload the Android APK to Google Play. I've created a google services account and given it the requested access.
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