Skip to content
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
1 change: 1 addition & 0 deletions sdk/identity/Azure.Identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
- Fixed an issue where setting `DefaultAzureCredentialOptions.TenantId` twice throws an `InvalidOperationException` ([#47035](https://github.com/Azure/azure-sdk-for-net/issues/47035))

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ public string TenantId
get => _tenantId.Value;
set
{
if (_interactiveBrowserTenantId.Updated && value != _interactiveBrowserTenantId.Value)
if (_interactiveBrowserTenantId.Updated && _tenantId.Value != _interactiveBrowserTenantId.Value)
{
throw new InvalidOperationException("Applications should not set both TenantId and InteractiveBrowserTenantId. TenantId is preferred, and is functionally equivalent. InteractiveBrowserTenantId exists only to provide backwards compatibility.");
}

if (_sharedTokenCacheTenantId.Updated && value != _sharedTokenCacheTenantId.Value)
if (_sharedTokenCacheTenantId.Updated && _tenantId.Value != _sharedTokenCacheTenantId.Value)
{
throw new InvalidOperationException("Applications should not set both TenantId and SharedTokenCacheTenantId. TenantId is preferred, and is functionally equivalent. SharedTokenCacheTenantId exists only to provide backwards compatibility.");
}

if (_visualStudioTenantId.Updated && value != _visualStudioTenantId.Value)
if (_visualStudioTenantId.Updated && _tenantId.Value != _visualStudioTenantId.Value)
{
throw new InvalidOperationException("Applications should not set both TenantId and VisualStudioTenantId. TenantId is preferred, and is functionally equivalent. VisualStudioTenantId exists only to provide backwards compatibility.");
}

if (_visualStudioCodeTenantId.Updated && value != _visualStudioCodeTenantId.Value)
if (_visualStudioCodeTenantId.Updated && _tenantId.Value != _visualStudioCodeTenantId.Value)
{
throw new InvalidOperationException("Applications should not set both TenantId and VisualStudioCodeTenantId. TenantId is preferred, and is functionally equivalent. VisualStudioCodeTenantId exists only to provide backwards compatibility.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,26 @@ public void ValidateAzureAdditionallyAllowedTenantsEnvVarDefaultHonored(string e
}

[Test]
public void ValidateShallowCloneCopiesAllProperties([Values]bool useTenantId)
public void DeprecatedTenantIdPropertiesCannotMismatch()
{
var options = new DefaultAzureCredentialOptions();
options.TenantId = "1";
Assert.Throws<InvalidOperationException>(() => options.InteractiveBrowserTenantId = "2");
Assert.Throws<InvalidOperationException>(() => options.SharedTokenCacheTenantId = "2");
Assert.Throws<InvalidOperationException>(() => options.VisualStudioTenantId = "2");
Assert.Throws<InvalidOperationException>(() => options.VisualStudioCodeTenantId = "2");
}

[Test]
public void TenantIdCanBeSetTwice()
{
var options = new DefaultAzureCredentialOptions();
options.TenantId = "1";
options.TenantId = "2";
}

[Test]
public void ValidateShallowCloneCopiesAllProperties([Values] bool useTenantId)
{
Random rand = new Random();

Expand Down