Get-udauthorizationpolicy: internal variables for this cmdlet are not available. Ensure that you are running this within an endpoint

Hi,
I use get-udauthorizationpolicy on one of my pages to list out the applied policies to the visiting user.
It looks like this:

New-UDCard -Id "Card_ListAuthPolicies" -Title "Currently applied AuthPolicies:" -Endpoint {
                $PolicyCheck = Get-UDAuthorizationPolicy
                    Foreach ($policy in $PolicyCheck) {
                        New-UDParagraph -text $policy
                    }
}

This works as expected. However I’ve noticed that the first time visiting my site for example, after an app pool recycle (scheduled nightly at 2am), I always see the following error on my card:

get-udauthorizationpolicy: internal variables for this cmdlet are not available. Ensure that you are running this within an endpoint

If I then refresh the page, it loads as normal, and the error does not reoccur until the next time the site recycles. Is this a bug? has anyone else seen similar or been able to replicate this?

Have tried it with a clean start - logout and login after restart the application?

Weirdly I cant seem to replicate this issue myself, e.g if I manually recycle the app pool then revisit the page. I only tend to notice it in the mornings and assume its to do with the nightly app pool recycle.

I’ve got pass through windows auth enabled and this happens when I visit the site first thing however I do wonder if maybe it could be browser/cache related so I’ll test this tomorrow morning and clear my cache before I try.

1 Like

You might also want to try the last nightly build. There was an issue with Windows Auth, IIS and auth policies where the $Session scope would not be initialized until after running the auth policies. A second refresh would ensure that the session scope was initialized.

Worth a shot. Might be related.

In 2.9.0 i still get this error. Was the fix from the nightly build you mentioned part of 2.9.0?
After the second refresh, it is working as expteced.

[Warn] PowerShellExecutionService Error executing endpoint NavigationMenu. Get-UDAuthorizationPolicy: Internal variables for this cmdlet are not available. Ensure that you are running this within an Endpoint.

ID NavigationMenu:

$Navigation = New-UDSideNav -Id "NavigationMenu" -Endpoint {
      param($User)
      $Policies = Get-UDAuthorizationPolicy
      if ($Policies -contains "DashboardAdmins")
      {
      ...
      }
}

Yes, it was. This issue must be unrelated to that change then and likely just a bug we need to squash.