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.

Add support for Service Account authentication with JSON Key File

See original GitHub issue
Service account authentication can be done directly with .p12 files or with 
JSON Key files.

Currently, the .NET library only supports .p12 files.   This feature requests 
is to add support for JSON key files

see
https://cloud.google.com/storage/docs/authentication#generating-a-private-key


Some additional references for JSON key files in java and go libraries:

https://code.google.com/p/google-api-java-client/source/browse/google-api-client
/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleCredential.jav
a#776
https://github.com/golang/oauth2/issues/20
https://issues.jenkins-ci.org/browse/JENKINS-24571

cross reference with:  
https://code.google.com/p/google-api-dotnet-client/issues/detail?id=280


Original issue reported on code.google.com by salrashi...@gmail.com on 23 Feb 2015 at 7:18

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17

github_iconTop GitHub Comments

12reactions
sergey-tihoncommented, May 6, 2016

The full source code should be like this

GoogleCredential credential;
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
    credential = GoogleCredential.FromStream(stream)
        .CreateScoped(VisionService.Scope.CloudPlatform);
}

var service = new VisionService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "my-app-name",
});
3reactions
samofwisecommented, Jul 11, 2016

How do you define a user to impersonate? For the Directory Service this is how I used to do it with a .p12 file:

var certificate = new X509Certificate2(HttpContext.Current.Server.MapPath(relativeKeypath), "notasecret", X509KeyStorageFlags.Exportable);

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

If I don’t specify a User I get an Invalid Credentials [401] error. How do I do this now?

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 >
Best practices for managing service account keys - IAM
Service account keys created by using the Google Cloud console or the gcloud CLI are JSON files, and you can copy these files...
Read more >
How can I get the file "service_account.json" for Google ...
If "service account key" isn't an option · log in to your GCP account · Go to the "IAM & Admin" -> Service...
Read more >
Generate service account key in Google Cloud Platform ...
Click the 'ADD KEY' dropdown, select 'Create New Key' and select JSON as the key type. The service account key JSON file is...
Read more >
Create a service account JSON file
How to create a service account JSON file to authenticate Site24x7 for discovery of GCP resources? · Hover on IAM & Admin >...
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