Skip to content

Commit 0842f89

Browse files
authored
[Extensions] Fixing managed identity error text (#53415)
* [Extensions] Fixing managed identity error text The focus of these changes is to improve the error messaging when configuration provided for one of the managed identity credentials is incorrect.
1 parent a004ad8 commit 0842f89

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

sdk/extensions/Microsoft.Extensions.Azure/src/Internal/ClientFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ internal static TokenCredential CreateCredential(IConfiguration configuration)
178178
return new WorkloadIdentityCredential(workloadIdentityOptions);
179179
}
180180

181-
throw new ArgumentException("For workload identity, 'tenantId', 'clientId', and 'tokenFilePath' must be specified via environment variables or the configuration.");
181+
throw new ArgumentException("For workload identity, 'tenantId', 'clientId', and 'tokenFilePath' must be specified via the configuration.");
182182
}
183183

184184
if (string.Equals(credentialType, "managedidentityasfederatedidentity", StringComparison.OrdinalIgnoreCase))
@@ -189,7 +189,7 @@ internal static TokenCredential CreateCredential(IConfiguration configuration)
189189
string.IsNullOrWhiteSpace(clientId) ||
190190
string.IsNullOrWhiteSpace(azureCloud))
191191
{
192-
throw new ArgumentException("For managed identity as a federated identity credential, 'tenantId', 'clientId', 'azureCloud', and one of ['managedIdentityClientId', 'resourceId', 'objectId'] must be specified via environment variables or the configuration.");
192+
throw new ArgumentException("For managed identity as a federated identity credential, 'tenantId', 'clientId', 'azureCloud', and one of ['managedIdentityClientId', 'managedIdentityResourceId', 'managedIdentityObjectId'] must be specified via the configuration.");
193193
}
194194

195195
if (!string.IsNullOrWhiteSpace(resourceId))
@@ -413,8 +413,8 @@ private static void AssertSingleManagedIdentityIdentifier(string clientId, strin
413413
idCount += string.IsNullOrWhiteSpace(objectId) ? 0 : 1;
414414

415415
var validIdentifiers = isFederated
416-
? "'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'"
417-
: "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'";
416+
? "'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'"
417+
: "'clientId', 'managedIdentityClientId', 'managedIdentityResourceId', or 'managedIdentityObjectId'";
418418

419419
if (idCount > 1)
420420
{
@@ -423,7 +423,7 @@ private static void AssertSingleManagedIdentityIdentifier(string clientId, strin
423423

424424
if (isFederated && idCount < 1)
425425
{
426-
throw new ArgumentException($"At least one of [{validIdentifiers}] must be specified for managed identity.");
426+
throw new ArgumentException($"A clientId and exactly one of [{validIdentifiers}] must be specified for federated managed identity.");
427427
}
428428
}
429429

0 commit comments

Comments
 (0)