Dashboard calls to Rest API as authenticated user

Product: PowerShell Universal
Version: 1.5.9

I feel like I’m missing something simple but can’t find a solution to this. I want to start separating commonly used commands/endpoints I have in a Dashboard, and put them as Rest API endpoints. Everything is going to require Auth to run and certain API endpoints could have different permissions for them. My idea was to make all the API endpoints, set their auth role level and on the dashboard side do a Invoke-RestMethod to the API. As the user, I get a 401 unauthorized error doing that, which is understandable, but how can I provide my users’ session cookie to the invoke-restmethod? We’re using Azure AD Auth.

In 1.5.11 we’ve added a $Cookies hashtable to dashboards so you’ll be able to get that session cookie and pass it to Invoke-RestMethod. I think in 1.5.10 you have access to $Headers so you should be able to get the cookie then but 1.5.11 will make it easier.

Thanks for the quick reply Adam. I know 1.5.10 just came out, but do you guys have a ball park for 1.5.11 release? At the moment, can’t develop on 1.5.10 as our Azure AD Auth isn’t working with that version.

Later this week. We need to fix a few more important issues. Nightly builds will have the fixes listed here: Changelog - PowerShell Universal

You guys are awesome, really appreciate all the work you guys put into your products.

This works perfectly on 1.5.11 thanks, just passed the $headers variable to invoke-restmethod.

image

image

1 Like