Skip to content

Add GetTokenOptions #2629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add GetTokenOptions #2629

wants to merge 1 commit into from

Conversation

chlowell
Copy link
Member

Closes #2566

@chlowell chlowell self-assigned this May 22, 2025
@chlowell chlowell added the Azure.Identity The azure_identity crate label May 22, 2025
@github-actions github-actions bot added Azure.Core The azure_core crate Cosmos The azure_cosmos crate labels May 22, 2025
Copy link

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure_core
azure_identity

@chlowell chlowell marked this pull request as ready for review May 22, 2025 22:18
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 22:18
Copy link
Contributor

@Copilot Copilot AI left a comment

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 extends the TokenCredential API to accept an optional GetTokenOptions parameter and updates all existing credentials, cache logic, and examples to propagate it (using None by default). It also refactors the token cache to pass options through to the fetch callback.

  • Extend TokenCredential::get_token to accept Option<GetTokenOptions> and add the GetTokenOptions type.
  • Update every credential implementation (and calling sites) to accept and forward the new options parameter.
  • Refactor TokenCache to accept and pass options to the provided callback function.

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

File Description
sdk/core/azure_core/src/credentials.rs Added GetTokenOptions and updated trait signature
sdk/identity/azure_identity/src/credentials/cache.rs Refactored cache to accept options and callback
sdk/identity/azure_identity/src/credentials/imds_managed_identity_credentials.rs Updated get_token signature and calls
Comments suppressed due to low confidence (1)

sdk/identity/azure_identity/src/credentials/cache.rs:30

  • [nitpick] No tests currently pass a non-None GetTokenOptions through the cache. Consider adding a test case that supplies a real GetTokenOptions to ensure it is correctly propagated to the callback.
pub(crate) async fn get_token<'a, C, F>(

impl TokenCache {
pub(crate) fn new() -> Self {
Self(RwLock::new(HashMap::new()))
}

pub(crate) async fn get_token(
pub(crate) async fn get_token<'a, C, F>(
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider renaming the callback parameter to a more descriptive name, such as fetch_fn, to clarify that it is responsible for fetching a fresh token when the cache misses or expires.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core The azure_core crate Azure.Identity The azure_identity crate Cosmos The azure_cosmos crate
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

Add options type for TokenCredential::get_token
1 participant