Invoking Custom REST API from dashboard

I’m trying to access a custom API with authentication from a Dashboard.

I’ve searched around and found a post suggesting you could pass the $Headers variable to the headers parameter but that results in an error “The header name format is invalid”, I eventually found out that it’s a dictionary(System.Collections.Generic.Dictionary`2) instead of a Hashtable, no clue if that’s could be the issue or not.

I then tried passing just the cookie, both using -Header @{Cookie=$Cookie} -Header $Cookie and -Header @{Cookie=$Headers[‘Cookie’]} but all result in a 401.

I’m using WS-Federation as the authentication, and running PSU standalone. Any idea of what I’m doing wrong? It all works fine with Pages, unfortunately it doesn’t really support the usecase I want so that’s not an option for me.

Product: PowerShell Universal
Version: 3.0.0-rtm1

I’d suggest turning on GrantAppToken and then using an app token rather than a cookie.

Once you have that on, you can use the app token to call the REST API with the user’s credentials. The $PSUAppToken variable will be automatically defined with the app token’s contents.

Invoke-RestMethod http://localhost:5000/myapi -Headers @{
  Authorization = "Bearer $PSUAppToken"
}

Thanks for the tip, I had dismissed it because I thought it was for Universal’s own internal APIs and not APis in general :smile: