API Authentication Token in PowerShell
I'm trying to get an API auth token with a User-based server Application in PowerShell, and I'm getting an "invalid_client" error.
The client ID is definitely correct, and I've tried a few different ways of making the call.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
$CLIENTID = "****"
$CLIENTSECRET = ""****"
$Text = "$($CLIENTID):$($CLIENTSECRET)"
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)
$EncodedText =[Convert]::ToBase64String($Bytes)
$AuthHeader = @{"Content-Type" = "application/x-www-form-urlencoded"
"Authorization" = "Basic $($EncodedText)"
}
$AuthBody = @{"Grant_type" = "password"
"Scope" = "API"
"Username" = ""****"
"Password" = ""*****"
}
$uri = "https://penncareylaw.hosted.panopto.com/Panopto/oauth2/connect/token"
$request = Invoke-RestMethod -Method POST -Uri $uri -Body $AuthBody -Headers $AuthHeader
I'm stumped - does anyone know how to make this call in PowerShell?
Thanks!
Best Answer
-
Nedim Deliahmetovic Panopto Employee
Hi Amelia,
I am sorry that you still have issues.
The error "invalid_client" is mostly related to the invalid data about client (client id, client secret or grant type).
Can you please try to get Access Token using Postman with your client id, client secret and username and password? I am sharing with you required Posman values for request:
If you are unable to get AccessToken using Postman, try to regenerate Client Secret for Client that you are using and please verify that generated client secret is copied without extra spaces.
Regards.
Nedim
1
Answers
Hi Amelia,
Thank you for contacting Panopto. I am Nedim and I will try to help you with PowerShell script to get AccessToken.
Here is a script code that you can use:
I hope this will help you.
Please let us know if you have additional questions.
Regards.
Nedim
Thanks Nedim for providing the code example, but it's unfortunately incomplete. What should be in the $headers variable?
Hi Amelia,
You can add following header but it works without header too:
Have you tried code without header that I provided in the previous post? Does it work for you without header?
I hope this will help.
Regards.
Hi Nedim,
Thanks for providing header values. Unfortunately, I'm still getting the "invalid_client" error regardless of if I include or exclude the header.
I've confirmed that the username and password are correct (tested logging in with them), and I also double checked the client ID and secret for the User Based Server Application (the app is enabled and CORS Origin URL is https://penncareylaw.hosted.panopto.com, see attached screenshot).
Do you have any other ideas for how to resolve this?
Thank you,
Amelia
Hi Nedim,
Thanks - I generated a new API client and was able to get the access token in Postman and with PowerShell. There must have been something wrong with the API client I created.
Thanks for helping me get connected to the API!
Amelia