Skip to content

fix(authentication-azure): preserve caller-owned async credentials - #732

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
rksharma-owg:codex/preserve-async-credentials
Sep 11, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
rksharma-owg:codex/preserve-async-credentials

Conversation

@rksharma-owg

Copy link
Copy Markdown
Contributor

AzureIdentityAccessTokenProvider closes an async credential immediately after retrieving a token. Reusing that credential for a later request, sharing it across providers, or acquiring tokens concurrently can then fail because its transport is already closed.

Leave the caller-owned credential open after token acquisition, matching the synchronous path. Document that the application must close it after all clients have finished, using its async context manager or await credential.close().

Validation (Python 3.12):

  • Three regressions failed on the original code: sequential requests, two providers sharing one credential, and concurrent requests. Tests use a credential double with an observable closed state and exercise the real provider; no live Azure credentials or network calls are needed.
  • Authentication Azure package: pytest -q — 21 passed.
  • YAPF, isort, mypy, wheel build, and git diff --check passed.
  • Pylint exited successfully with 10/10; it also reports the existing unrecognized suggestion-mode configuration option.

Closes #528. Related lifetime discussion: #365.

Prepared with AI assistance; reproduction and validation ran locally.

@sonarqubecloud

Copy link
Copy Markdown

@baywet Vincent Biret (baywet) 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.

Thanks for the contribution!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review issues were identified, and validation covers the credential lifetime changes.

Pull request overview

Preserves caller-owned async Azure credentials for reuse and concurrent requests, while documenting caller-managed cleanup.

Changes:

  • Removed implicit credential closure.
  • Added regression tests for reuse, sharing, and concurrency.
  • Documented credential lifetime responsibilities.
File summaries
File Description
packages/authentication/azure/tests/test_azure_identity_access_token_provider.py Tests credential reuse and concurrency.
packages/authentication/azure/README.md Documents caller-managed cleanup.
packages/authentication/azure/kiota_authentication_azure/azure_identity_access_token_provider.py Preserves credential lifetime.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@baywet
Vincent Biret (baywet) merged commit 9893377 into microsoft:main Sep 11, 2026
52 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

Async AzureIdentityAccessTokenProvider closes credential after every get_token breaking concurrent requests

3 participants