How do I get the email name of the current user retrieved via default credential fetching

1.7k Views Asked by At

I am not using a JSON key. I use the default credential loading mechanism that is used when you create any new client.

But what means is there to reflect on the current creds?

import google.auth
creds, project = google.auth.default()

# I can get the project id
print(project)

# I can get the oauth stuff
print(creds.client_secret)
print(creds.client_id)

But how do I get the email name of the user or Google service account that is currently active?

I tried this

print(creds.service_account_email)

But it returns an error:

AttributeError: 'Credentials' object has no attribute 'service_account_email'

This is suppose to be a property of the class.

I want to get the email name of the user or google service account.

Edit

Related to this post: Programmatically get current Service Account on GCP

From an example in that post, is there a way to get the user's email name if it's not a GSA?

import google.auth

credentials, project_id = google.auth.default()

if hasattr(credentials, "service_account_email"):
  print(credentials.service_account_email)
else:
    print("WARNING: no service account credential. User account credential?")
0

There are 0 best solutions below