Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set the scopes when creating an access token using `gcloud auth`

I see in example Java codes there are possibilities to add scopes when one is requesting a refresh of a token:

credential.createScoped(Arrays.asList("someapi")).refreshToken

I saw the same in Python. But there is no configuration option for scopes in the cli.

gcloud auth application-default print-access-token

There is no gcloud auth --scopes="someapi" application-default print-access-token

Do you know how do I set up an access key for custom scopes in the cli?

like image 507
Hunor Kovács Avatar asked Sep 05 '25 03:09

Hunor Kovács


2 Answers

In the API, as in the gcloud auth print-access-token command, if you set a scope on a user account, it will fail. Only the service account can be scoped, not the user account.

In fact you can set scope on your user account credential like that gcloud auth application-default login --scopes=... And then, when you will generate a token, it will be automatically scoped correctly.

Keep in mind that you especially need to scope your credentials to access to no Google Cloud API (Workspace, Maps, Youtube,...)

like image 178
guillaume blaquiere Avatar answered Sep 07 '25 19:09

guillaume blaquiere


You can do it using the --scopes flag. It's not in the help but it works. The command looks like gcloud auth print-access-token [email protected] --scopes='https://www.googleapis.com/auth/travelpartner'

like image 21
Javier Pazos Avatar answered Sep 07 '25 20:09

Javier Pazos