Skip to content

Commit 0b97625

Browse files
[Identity] Add BrokerCredential as part of the dev credentials (#51944)
* Add Broker Credential to the dev credential chains * Update Changelog * Update sdk/identity/Azure.Identity/CHANGELOG.md Co-authored-by: Scott Addie <[email protected]> * Modify test for new behaviour * Always include the Broker in the chain * Revert "Always include the Broker in the chain" This reverts commit befec4a. --------- Co-authored-by: Scott Addie <[email protected]>
1 parent 86669eb commit 0b97625

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

sdk/identity/Azure.Identity.Broker/tests/DefaultAzureCredentialFactoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void ValidateDefaultAzureCredentialAZURE_TOKEN_CREDENTIALS_Honored_WithBr
5757
Assert.IsTrue(chain.Any(cred => cred is VisualStudioCredential));
5858
Assert.IsTrue(chain.Any(cred => cred is AzureDeveloperCliCredential));
5959
Assert.IsTrue(chain.Any(cred => cred.GetType() == typeof(VisualStudioCodeCredential)));
60-
Assert.IsFalse(chain.Any(cred => cred.GetType() == typeof(InteractiveBrowserCredential)));
60+
Assert.IsTrue(chain.Any(cred => cred.GetType() == typeof(InteractiveBrowserCredential)));
6161
}
6262
else if (credSelection == Constants.ProdCredentials)
6363
{

sdk/identity/Azure.Identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs Fixed
1010

1111
- Fixed `AzureDeveloperCliCredential` hanging when the `AZD_DEBUG` environment variable is set by adding the `--no-prompt` flag to prevent interactive prompts ([#52005](https://github.com/Azure/azure-sdk-for-net/issues/52005)).
12+
- `BrokerCredential` is now included in the chain when `AZURE_TOKEN_CREDENTIALS` is set to `dev` and the `Azure.Identity.Broker` package is installed.
1213

1314
### Other Changes
1415

sdk/identity/Azure.Identity/src/DefaultAzureCredentialFactory.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,21 @@ public TokenCredential[] CreateCredentialChain()
3838
{
3939
if (_useDevCredentials)
4040
{
41-
return
42-
[
41+
var devCredentials = new List<TokenCredential>
42+
{
4343
CreateVisualStudioCredential(),
4444
CreateVisualStudioCodeCredential(),
4545
CreateAzureCliCredential(),
4646
CreateAzurePowerShellCredential(),
4747
CreateAzureDeveloperCliCredential()
48-
];
48+
};
49+
50+
if (TryCreateDevelopmentBrokerOptions(out InteractiveBrowserCredentialOptions brokerOptions))
51+
{
52+
devCredentials.Add(CreateBrokerCredential(brokerOptions));
53+
}
54+
55+
return devCredentials.ToArray();
4956
}
5057
else if (_useProdCredentials)
5158
{
@@ -98,6 +105,10 @@ public TokenCredential[] CreateCredentialChain()
98105
{
99106
chain.Add(CreateManagedIdentityCredential());
100107
}
108+
if (!Options.ExcludeBrokerCredential && TryCreateDevelopmentBrokerOptions(out InteractiveBrowserCredentialOptions brokerOptions))
109+
{
110+
chain.Add(CreateBrokerCredential(brokerOptions));
111+
}
101112
}
102113

103114
if (!_useProdCredentials)

0 commit comments

Comments
 (0)