Skip to content

Commit 2493a6d

Browse files
azure-sdkbenbp
andauthored
Source user object id directly instead of with graph (#42374)
Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent 2edd07f commit 2493a6d

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,12 @@ try {
353353
# Make sure the provisioner OID is set so we can pass it through to the deployment.
354354
if (!$ProvisionerApplicationId -and !$ProvisionerApplicationOid) {
355355
if ($context.Account.Type -eq 'User') {
356-
# Support corp tenant and TME tenant user id lookups
357-
$user = Get-AzADUser -Mail $context.Account.Id
358-
if ($null -eq $user -or !$user.Id) {
359-
$user = Get-AzADUser -UserPrincipalName $context.Account.Id
360-
}
361-
if ($null -eq $user -or !$user.Id) {
356+
# HomeAccountId format is '<object id>.<tenant id>'
357+
$userAccountId = (Get-AzContext).Account.ExtendedProperties.HomeAccountId.Split('.')[0]
358+
if ($null -eq $userAccountId) {
362359
throw "Failed to find entra object ID for the current user"
363360
}
364-
$ProvisionerApplicationOid = $user.Id
361+
$ProvisionerApplicationOid = $userAccountId
365362
} elseif ($context.Account.Type -eq 'ServicePrincipal') {
366363
$sp = Get-AzADServicePrincipal -ApplicationId $context.Account.Id
367364
$ProvisionerApplicationOid = $sp.Id
@@ -431,17 +428,14 @@ try {
431428
Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when -ServicePrincipalAutth is not set."
432429
}
433430

434-
# Support corp tenant and TME tenant user id lookups
435-
$userAccount = (Get-AzADUser -Mail (Get-AzContext).Account.Id)
436-
if ($null -eq $userAccount -or !$userAccount.Id) {
437-
$userAccount = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account)
438-
}
439-
if ($null -eq $userAccount -or !$userAccount.Id) {
431+
$userAccountName = (Get-AzContext).Account.Id
432+
# HomeAccountId format is '<object id>.<tenant id>'
433+
$userAccountId = (Get-AzContext).Account.ExtendedProperties.HomeAccountId.Split('.')[0]
434+
if ($null -eq $userAccountId) {
440435
throw "Failed to find entra object ID for the current user"
441436
}
442-
$TestApplicationOid = $userAccount.Id
437+
$TestApplicationOid = $userAccountId
443438
$TestApplicationId = $testApplicationOid
444-
$userAccountName = $userAccount.UserPrincipalName
445439
Log "User authentication with user '$userAccountName' ('$TestApplicationId') will be used."
446440
}
447441
# If user has specified -ServicePrincipalAuth

0 commit comments

Comments
 (0)