I have two projects running locally which both use Application Default Credentials. One is in Spring Boot and one is in NodeJS. They use different projects on my same GCP account.
The NodeJS one was working fine and using Google's auth library to authenticate and then use the Google Sheets API.
I then started the Spring Boot one which points to a GCP SQL server. To get this working, I had to change the project that the gcloud CLI was referring to, and then run gcloud auth application-default login. This then worked and I was able to access everything needed for this app.
When trying to move back to the NodeJS project I was unable to authenticate, which I expected. However, when I pointed the gcloud CLI back to this project and ran gcloud auth application-default login again, I was still unable to authenticate. I also expected the Spring Boot app to fail again, but it still worked.
There are two interesting lines in the console when I start up the Spring Boot app:
c.g.c.s.core.DefaultCredentialsProvider : Scopes in use by default credentials: [{Scopes for Spring Boot App}]
c.g.c.s.a.c.GcpContextAutoConfiguration : The default project ID is {MYNODEJSAPP}
Why have the default credentials retained the wrong scope despite changing to the correct project ID?
Also, is there a better way to manage two sets of ADCs locally than needing to keep switching the project in the CLI?
service account keyjson files on you personal laptop which is a bit stupid. Impersonation should be the solution which can/should be backed by an SSO/MFA flow