Search code examples
pythongoogle-apigoogle-authentication

How to discover the scope associated to my Google API credentials?


I'm using Google earthengine to run GIS computations. recently Google added projects to manages the created assets which means that I need to use the Google cloud API to find back my projet name.

I use a service account to connect to the API but for I don't manage to get access to my project list. I'm sure that I've add the "https://www.googleapis.com/auth/cloudplatformprojects.readonly" scope to my account though.

Is there a way for me to check using the API the list of my current scopes ?

import ee 

ee.Iniitialize() 

# that's the credential I would like to test 
# it's a ServiceAccountCredential like any other Google API (I use it to connect to drive as well)
cred = ee.Credentials()

# something like 
for scope in cred.scopes(): 
    print(scope)

Solution

  • You can lookup access and identity tokens from Google's OAuth service tokeninfo method:

    • https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={access_token}
    • https://www.googleapis.com/oauth2/v1/tokeninfo?id_token={id_token}

    And there's a Google CLI "OAuth tool" oauth2l that you find useful too.

    It includes (among other things) an oauth2l info method