google-auth-library-java icon indicating copy to clipboard operation
google-auth-library-java copied to clipboard

fix: ComputeEngineCredentials.createScoped should invalidate existing AccessToken

Open zhumin8 opened this issue 1 year ago • 1 comments

Fixes #1387 ☕️

As described in the original issue, this looks like a regression introduced in https://github.com/googleapis/google-auth-library-java/commit/7e268611d2c2152e84702b1c67ca846902bbe2d5 when migrating from deprecated constructor to use builder. Access token is scoped and should be invalidated when scope changes.

This PR include changes:

  • ComputeEngineCredentials.createScoped() should invalidate existing AccessToken
  • ComputeEngineCredentials.createScoped(newScopes, newDefaultScopes) should respect universe domain settings.
  • For testing, update to mock transport to support returning access token when url is scoped. Should return a different access token compared to default url with no scopes.
  • ~~Other credential types: e.g. ServiceAccountCredentials.creatScoped() should also invalidate existing AccessToken~~ Will raise separate pr for this.

Follow up items not included in this PR:

  • Check if other GoogleCredentials subclasses that overrides createScoped() suffer from same issue (e.g. ServiceAccountCredentials.creatScoped() )

zhumin8 avatar Jul 03 '24 15:07 zhumin8