Skip to content

App authentication expires after 60 minutes in Az Automation, further calls fail #115

@RTTrickster

Description

@RTTrickster

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions