Skip to content
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

Fix that RemoveUser doesn't work when create Public Client with broker #27448

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

Conversation

msJinLei
Copy link
Contributor

@msJinLei msJinLei commented Mar 26, 2025

Description

The test cases to cover

I and II

[wam enabled and wam disabled]

  • login with 2 accounts
  • get-azcontext -listavailable
  • export
  • disconnect-azaccount one by one
III and IV

[wam enabled and wam disabled]

  • login with 2 accounts
  • get-azcontext -listavailable
  • clear-azcontext
V
  • disable WAM
  • login the first account
  • enable WAM
  • login the second account
  • get-azcontext -listavailable
  • disconnect the first account
  • disconnect the second account
VI
  • disable WAM
  • login the first account
  • enable WAM
  • login the second account
  • get-azcontext -listavailable
  • disconnect the second account
  • disconnect the first account
VII
  • disable WAM
  • login the first account
  • enable WAM
  • login the second account
  • get-azcontext -listavailable
  • clear-azcontext
VIII
  • enable WAM
  • login the first account
  • disable WAM
  • login the second account
  • clear-azcontext

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • For SDK-based development mode, update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • For autorest-based development mode, include the changelog in the PR description.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@msJinLei msJinLei requested a review from Copilot March 27, 2025 02:24
Copy link

@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 addresses an issue with RemoveUser when creating a public client with broker support, by propagating an authority parameter through various authentication calls. Key changes include:

  • Introducing new RemoveUser overloads that accept an authority string in the authentication factories and mocks.
  • Propagating the authority parameter to public client creation and token cache removal methods.
  • Updating related context and cache clearing logic to use the provided authority.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Accounts/Authentication/Factories/AuthenticationFactory.cs Added RemoveUser overload and updated RemoveFromTokenCache to pass authority.
src/Accounts/Accounts/Context/GetAzureRMContext.cs Updated context refresh logic by setting the environment property before refreshing contexts.
src/Accounts/Accounts/Account/DisconnectAzureRmAccount.cs Changed RemoveUser call to pass the authority from the current context.
src/Accounts/Accounts/Context/RemoveAzureRmContext.cs Updated TryRemoveAccount call to include the authority parameter.
tools/TestFx/Mocks/MockTokenAuthenticationFactory.cs
tools/TestFx/Mocks/MockCertificateAuthenticationFactory.cs
Added new RemoveUser overloads that throw NotImplementedException.
src/Accounts/Accounts/Context/ClearAzureRmContext.cs Updated clearing of token cache to pass the authority from the default context.
src/Accounts/Authentication/ResourceManager/AzureRmProfile.cs Updated authority handling in RefreshContextsFromCache and maintained a fixme comment regarding Connect-AzAccount.
src/Accounts/Authentication/Authentication/TokenCache/InMemoryTokenCacheProvider.cs
SharedTokenCacheProvider.cs
PowerShellTokenCacheProvider.cs
Changed ClearCache and other token cache related methods to accept an authority parameter.
Comments suppressed due to low confidence (2)

src/Accounts/Accounts/Context/GetAzureRMContext.cs:87

  • Add null checks for 'DefaultProfile.DefaultContext' and its 'Environment' property to prevent potential NullReferenceException when accessing Environment.Name.
AzureSession.Instance.SetProperty(AzureSession.Property.Environment, DefaultProfile.DefaultContext.Environment.Name);

src/Accounts/Authentication/ResourceManager/AzureRmProfile.cs:825

  • Verify that concatenating 'organizations' directly to ActiveDirectoryAuthority produces a valid authority URL; consider inserting a '/' if required.
authority = "${sessionEnvironment.ActiveDirectoryAuthority}organizations";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant