Before I describe my problem, I want to clarify that I am not an Azure expert. So please excuse me if I say something wrong.
I have a PowerShell Azure Function that is secured with AAD. In my script (Az Funciton) I can get the accessToken and the AccountId from the request Header:
#Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
$accountId = $Request.Headers['x-ms-client-principal-name']
$accessToken = $Request.Headers['x-ms-token-aad-access-token']
On my script, I use the Power Shell Az module and I want to connect to Azure with the following command:
Connect-AzAccount -AccessToken $accessToken -AccountId $accountId
Unfortunately, the connection to Azure is not working properly, I get the following error:
Unable to acquire token for tenant 'organizations' with error 'Authentication failed.'
I understood that it's not the right accessToken to use. Is it possible to have the right AccessToken and so use the Connect-AzAccount command with AccessToken option ?
I want to specify that the PowerShell script must be executed with the identity of the user who is calling my Azure function. Is my approach correct or is there another way to implement the same scenario?
Thanks for your help, Mehdi