-
Notifications
You must be signed in to change notification settings - Fork 81
Description
When connecting to msgraph via app registration in Azure Automation, the authentication seems to expire after 60 minutes and all further calls fall. Suspect there is potentially an issue relating to token refresh or something along those lines.
Connection is successfully established via:
Write-Output 'Connecting to MS Graph for Intune'
$MyAppCredential = Get-AutomationPSCredential -Name 'RegisteredAppSecret'
$authority = “https://login.windows.net/$tenant”
$clientId = $runAsConnection.ApplicationId
$clientSecret = $MyAppCredential.GetNetworkCredential().Password
Update-MSGraphEnvironment -AppId $clientId -Quiet
Update-MSGraphEnvironment -AuthUrl $authority -Quiet
Connect-MSGraph -ClientSecret $ClientSecret -Quiet
This works perfectly as expected, but when running from Azure Automation fails after 60 minutes. The error details are:
Error: Failed to acquire token silently as no token was found in the cache. Call method AcquireToken
Error exception type: Microsoft.Intune.PowerShellGraphSDK.AdalAuthException
If I execute the process again immediately from scratch, including a new instance of connect-msgraph, it works again straight away till the next 60 minute timeout. In my particular use case, I am executing on a Hybrid Runbook Worker.
I can execute this same process interactively from my local PC (using standard user auth obviously: Connect-MSGraph -PSCredential $creds) and the process successfully runs to full completion with no 60 minute timeout.