Skip to content

Make Access token cache public#49712

Open
g2vinay wants to merge 11 commits into
Azure:mainfrom
g2vinay:make-token-cache-public
Open

Make Access token cache public#49712
g2vinay wants to merge 11 commits into
Azure:mainfrom
g2vinay:make-token-cache-public

Conversation

@g2vinay

@g2vinay g2vinay commented Jul 2, 2026

Copy link
Copy Markdown
Member

Makes AccessTokenCache Public

g2vinay added 3 commits July 2, 2026 11:00
Move AccessTokenCache from com.azure.core.implementation to the public
com.azure.core.credential package, alongside SimpleTokenCache. The class
is now part of the public API surface of azure-core.

Changes:
- Move AccessTokenCache.java to com.azure.core.credential package
- Add comprehensive public JavaDoc
- Update import in BearerTokenAuthenticationPolicy
- Move AccessTokenCacheTests to com.azure.core.credential test package
- Update import in TokenCacheTests
Copilot AI review requested due to automatic review settings July 2, 2026 18:13
@github-actions github-actions Bot added the Azure.Core azure-core label Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR promotes AccessTokenCache from the internal com.azure.core.implementation namespace into the public com.azure.core.credential API surface, and updates in-repo usages and tests accordingly.

Changes:

  • Moved AccessTokenCache to com.azure.core.credential and expanded its public JavaDoc.
  • Updated BearerTokenAuthenticationPolicy and test code to reference the new public package.
  • Added a CHANGELOG entry documenting the newly-public API.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/core/azure-core/src/test/java/com/azure/core/credential/TokenCacheTests.java Updates AccessTokenCache import to the new public package.
sdk/core/azure-core/src/test/java/com/azure/core/credential/AccessTokenCacheTests.java Moves the test into the com.azure.core.credential package.
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/BearerTokenAuthenticationPolicy.java Updates the policy to import AccessTokenCache from the public credential package.
sdk/core/azure-core/src/main/java/com/azure/core/credential/AccessTokenCache.java Promotes AccessTokenCache to a public package and adds extensive JavaDoc + sample.
sdk/core/azure-core/CHANGELOG.md Documents the promotion of AccessTokenCache as a feature addition.
Comments suppressed due to low confidence (2)

sdk/core/azure-core/src/test/java/com/azure/core/credential/AccessTokenCacheTests.java:8

  • These imports are from the same package as the test (com.azure.core.credential) and will be flagged by Checkstyle's RedundantImport rule (see eng/lintingconfigs/checkstyle/track2/checkstyle.xml:64-73). Remove the redundant imports.
    sdk/core/azure-core/src/main/java/com/azure/core/credential/AccessTokenCache.java:53
  • The embedded Javadoc sample contains very long lines (due to HTML entities) that are likely to exceed the repo's 120-character LineLength Checkstyle rule (see eng/lintingconfigs/checkstyle/track2/checkstyle.xml:53-59). Please wrap the sample statements similarly to other credential samples to avoid Checkstyle failures.

…ix imports

- Rename 'checkToForceFetchToken' to 'refreshOnContextChange' in public methods
  of AccessTokenCache, and propagate the rename to BearerTokenAuthenticationPolicy
  and PopTokenAuthenticationPolicy private helpers
- Fix getTokenSync @return Javadoc (was incorrectly saying 'Publisher')
- Add @throws IllegalArgumentException to both public getToken methods
- Add thread-safety guarantee and single-context limitation to class Javadoc
- Clarify refreshOnContextChange semantics and CAE use-case in class/param Javadoc
- Fix constructor null-check error message to follow SDK convention
- Fix internal null-check error messages to follow SDK convention
- Add AccessTokenCacheJavadocCodeSnippets.java for the src_embed marker
- Remove redundant same-package imports from AccessTokenCacheTests
- Fix stale constructor Javadoc and broken import in PopTokenAuthenticationPolicy
g2vinay added 4 commits July 17, 2026 12:14
…enAuthenticationPolicy

PopTokenAuthenticationPolicy uses com.azure.core.credential.AccessTokenCache which
is new in azure-core 1.59.0-beta.1. The azure-identity CI was building against the
published azure-core 1.58.1 (which doesn't have the public class), causing a compile
error.

- Add azure-core to AdditionalModules in sdk/identity/ci.yml so the identity CI
  builds it from source before compiling azure-identity-broker
- Add azure-core 1.59.0-beta.1 as a direct test dependency in azure-identity-broker
  pom so Maven resolves the locally built version over the transitive published one
@g2vinay g2vinay changed the title Make token cache public Make Access token cache public Jul 17, 2026
g2vinay added 2 commits July 17, 2026 14:53
- Use LOGGER.logThrowableAsError() instead of bare throw in retrieveTokenSync
  (ThrowFromClientLoggerCheck violation)
- Remove unused java.time.OffsetDateTime import from AccessTokenCacheJavadocCodeSnippets
  (UnusedImportsCheck violation)
…retrieveTokenSync

logThrowableAsError returns Throwable which cannot be thrown from a Supplier lambda.
Supplier.get() only throws RuntimeException, so narrowing the catch is correct.
Use logExceptionAsError which returns RuntimeException and compiles cleanly.
…e rethrowing

Error subclasses (OutOfMemoryError etc.) should also be caught. Since the Supplier
lambda can only propagate RuntimeException, non-RuntimeException Throwables are
wrapped in RuntimeException before being thrown through LOGGER.logExceptionAsError.

@vcolin7 vcolin7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time we spoke about making this class public you said you'd go back and revisit the design. It seems we're trying to make the class public as is. What other design choices did you explore and why did we go with simply exposing this class?

@g2vinay

g2vinay commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

Last time we spoke about making this class public you said you'd go back and revisit the design. It seems we're trying to make the class public as is. What other design choices did you explore and why did we go with simply exposing this class?

Making this class public is the first choice.
Second option was to revisit and update SimpleTokenCache class to offer same features as AccessTokenCache, which isn't possible, as its lambda based API contract isn't compatible with a TokenCredential one needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core azure-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants