Skip to content

Commit 7d38d2c

Browse files
authored
Properly initialize options for EnvironmentCredential sub credentials (Azure#22795)
* initialize options for EnvironmentCredential
1 parent c528635 commit 7d38d2c

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,21 @@ public class EnvironmentCredential : TokenCredential
4040
/// </summary>
4141
public EnvironmentCredential()
4242
: this(CredentialPipeline.GetInstance(null))
43-
{
44-
}
43+
{ }
4544

4645
/// <summary>
4746
/// Creates an instance of the EnvironmentCredential class and reads client secret details from environment variables.
4847
/// If the expected environment variables are not found at this time, the GetToken method will return the default <see cref="AccessToken"/> when invoked.
4948
/// </summary>
5049
/// <param name="options">Options that allow to configure the management of the requests sent to the Azure Active Directory service.</param>
5150
public EnvironmentCredential(TokenCredentialOptions options)
52-
: this(CredentialPipeline.GetInstance(options))
53-
{
54-
_options = options;
55-
}
51+
: this(CredentialPipeline.GetInstance(options), options)
52+
{ }
5653

57-
internal EnvironmentCredential(CredentialPipeline pipeline)
54+
internal EnvironmentCredential(CredentialPipeline pipeline, TokenCredentialOptions options = null)
5855
{
5956
_pipeline = pipeline;
57+
_options = options ?? new TokenCredentialOptions();
6058

6159
string tenantId = EnvironmentVariables.TenantId;
6260
string clientId = EnvironmentVariables.ClientId;

sdk/identity/Azure.Identity/tests/EnvironmentCredentialProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void CredentialConstructionClientCertificate()
7979
[Test]
8080
public void EnvironmentCredentialUnavailableException()
8181
{
82-
var credential = InstrumentClient(new EnvironmentCredential(CredentialPipeline.GetInstance(null), null));
82+
var credential = InstrumentClient(new EnvironmentCredential(CredentialPipeline.GetInstance(null)));
8383
Assert.ThrowsAsync<CredentialUnavailableException>(async () => await credential.GetTokenAsync(new TokenRequestContext(MockScopes.Default)));
8484
}
8585

0 commit comments

Comments
 (0)