401 with API or VS Code

Product: PowerShell Universal
Version: 3.9.13

I have been testing out PSU on my local machine and everything was working with an unlicensed version. Recently we purchased a license , i cannot get jwt auth or connect via VS Code.

I have created an app token with admin as the identity and Administrator as the role.

I pasted my token into VS Code and it 401s each time it tries to connect.

I manually recreated some endpoints from our test machine, and they will work of Authentication is turned off. With it turned on, i get a 401 despite using the described method to test.

$token = “mytoken”
Invoke-RestMethod http://psu01:5000/myapicall -Method GET -Headers @{ Authorization = “Bearer $token”}

I have an out of the box configuration otherwise.

What have I missed?

I don’t see anything obvious based on your description. Seems pretty basic.

Can you try bumping the logging up to debug for both levels in Settings\ General \ Diagnostics, reproduce the issue and share the logs?

I was having this issue as well.

I could not get the logging to work. I tried going to platform → logging and adding a file target with a level of debug but no file was ever generated.

Instead I launched the server from a console and read very fast.

The problem for me was that the token I created had no expiration date; I saw a warning flash by that authentication failed because token lifespan couldn’t be verified.

Creating a new token and setting a year lifespan fixed the problem for me.

1 Like

Thank you for posting this, it fixed the API token problem for me too :grinning: