From 54fdc0e2e1a428161f8de56b39a54f84ab7217a6 Mon Sep 17 00:00:00 2001 From: sudarsanan-krishnan Date: Wed, 7 Sep 2016 19:33:29 -0700 Subject: [PATCH] Getting ADobjectId from logged in user --- LogicAppConnectionAuth.ps1 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/LogicAppConnectionAuth.ps1 b/LogicAppConnectionAuth.ps1 index 4dbef21..726f968 100644 --- a/LogicAppConnectionAuth.ps1 +++ b/LogicAppConnectionAuth.ps1 @@ -6,7 +6,6 @@ Param( [string] $api = 'office365 | dropbox | dynamicscrmonline | etc.', [string] $ConnectionName = 'YourConnectionName', [string] $subscriptionId = '80d4fe69-xxxx-xxxx-a938-9250f1c8ab03', - [string] $ADobjectId = '59b2c08b-xxxx-xxxx-840a-2d6d1e19fe8a', [bool] $createConnection = $false ) #region mini window, made by Scripting Guy Blog @@ -35,10 +34,6 @@ Login-AzureRmAccount $subscription = Select-AzureRmSubscription -SubscriptionId $subscriptionId -#can try to automatically get objectId -# $user = Get-AzureRmADUser -Mail 'myemail@foo.com' -# $ADobjectId = $user.Id - #if the connection wasn't alrady created via a deployment if($createConnection) { @@ -56,8 +51,6 @@ $parameters = @{ "redirectUrl"= "https://ema1.exp.azure.com/ema/default/authredirect" } } -$parameters.parameters[0].Add("objectId", $ADobjectid) -$parameters.parameters[0].Add("tenantId", $subscription.Tenant.TenantId) #get the links needed for consent $consentResponse = Invoke-AzureRmResourceAction -Action "listConsentLinks" -ResourceId $connection.ResourceId -Parameters $parameters -Force @@ -72,9 +65,11 @@ $regex = '(code=)(.*)$' Write-output "Received an accessCode: $code" if (-Not [string]::IsNullOrEmpty($code)) { + $objectid = (Get-AzureRMADUser -Mail (Get-AzureRmContext).Account.Id).Id + $parameters = @{ } $parameters.Add("code", $code) - $parameters.Add("objectId", $ADobjectid) + $parameters.Add("objectId", $objectid) $parameters.Add("tenantId", $subscription.Tenant.TenantId) # NOTE: errors ignored as this appears to error due to a null response