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 allowed tenants for InteractiveBrowserCredential #22257

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sdk/azidentity/azidentity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,26 @@ func TestAdditionallyAllowedTenants(t *testing.T) {
}
})
}

t.Run(credNameBrowser, func(t *testing.T) {
c, err := NewInteractiveBrowserCredential(&InteractiveBrowserCredentialOptions{
AdditionallyAllowedTenants: test.allowed,
// this enables testing the credential's tenant resolution without having to authenticate
DisableAutomaticAuthentication: true,
})
require.NoError(t, err)
_, err = c.GetToken(context.Background(), tro)
if test.err {
// the specified tenant isn't allowed, so the error should be about that
require.ErrorContains(t, err, "AdditionallyAllowedTenants")
} else {
// tenant resolution should have succeeded because the specified tenant is allowed,
// however the credential should have returned a different error because automatic
// authentication is disabled
require.ErrorIs(t, ErrAuthenticationRequired, err)
}
})

for _, credName := range []string{credNameAzureCLI, credNameAzureDeveloperCLI} {
t.Run(fmt.Sprintf("DefaultAzureCredential/%s/%s", credName, test.desc), func(t *testing.T) {
typeName := fmt.Sprintf("%T", &AzureCLICredential{})
Expand Down
1 change: 1 addition & 0 deletions sdk/azidentity/interactive_browser_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func NewInteractiveBrowserCredential(options *InteractiveBrowserCredentialOption
}
cp.init()
msalOpts := publicClientOptions{
AdditionallyAllowedTenants: cp.AdditionallyAllowedTenants,
ClientOptions: cp.ClientOptions,
DisableAutomaticAuthentication: cp.DisableAutomaticAuthentication,
DisableInstanceDiscovery: cp.DisableInstanceDiscovery,
Expand Down