简体   繁体   中英

How to use Google Service Account json file in .NET 6

I'm trying to create a .NET 6 web app that connects to Google Cloud API's, and host my app on Azure

I've created a service account with "Owner" permission, downloaded the json file, and placed the json file in the root of my directory.

How can I instruct my app to use this when connecting to Google Cloud API?

I see that I can set a windows environment variable, but I want to do it in my solution since it will be uploaded to Azure cloud

How can I instruct my app to use this when connecting to Google Cloud API?

Refer to this code for example: Authenticating with a service account key file

BigQuery Client Example:

var credentials = GoogleCredential.FromFile(jsonPath);
var client = BigQueryClient.Create(projectId, credentials);

Note from GCP Authentication documentation :

Creating a service account key is a security risk that should be avoided if possible. If you must create a service account key, make sure you keep it secure. Anyone with access to the key can gain all of the access that's granted to the associated service account.

The recommended solution is Workload Identity Federation

Check this page for configuring Workload Identity Federation to access GCP resources from Azure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM