I won't repeat it all here: "Application Default Credentials provide a simple way to get authorization credentials for use calling Google APIs."
If you can use Application Default Credentials, do.
There is an extra step you will need to perform the before first using Application Default Credentials as your identity when calling APIs from your machine:
gcloud auth application-default login [[email protected]]
Here's why you'll prefer to use Application Default Credentials:
var scopes = new String[] {
CloudResourceManagerService.Scope.CloudPlatform
};
GoogleCredential credential = Task.Run(
() => GoogleCredential.GetApplicationDefaultAsync()
).Result;
if (credential.IsCreateScopedRequired)
{
credential = credential.CreateScoped(scopes);
}
...That's all the code you need to authorize calls to (any) Google Cloud API!
We'll use the credential
object in the next step to make calls against the Google service...