cyberark / epv-api-scripts

These API scripts enable CyberArk users to automate privileged account management task like account creation, user management, and more.
https://www.cyberark.com/best
Apache License 2.0
201 stars 176 forks source link

Unauthorised with WriteErrorException #70

Closed FanSauChing1996 closed 4 years ago

FanSauChing1996 commented 4 years ago

When making use of Export/Import Platform.ps1

managed to use the following command to get the token though:

C:\Users\Administrator\Desktop> Invoke-RestMethod -Method Post -Uri https://xx.xx.xxx.xxx/PasswordVault/API/Auth/Cyberark/Logon -Body '{"password": "Password", "username": "Username"} -ContentType "application/json"

However when i run the script as a whole I encounter C:\Users\Administrator\Desktop\ExportImportPlatform.ps1. : Unauthorized

AssafMiron commented 4 years ago

Can you provide more info on what line it errors? Can you run the script using -Debug -Verbose so we can see more info?

FanSauChing1996 commented 4 years ago

utput of -Debug -Verbose Export / Import Platform: Script Started VERBOSE: POST https://xx.xx.xxx.xxx/PasswordVault/api/auth/cyberark/logon with -1 byte payload VERBOSE: received 182-byte response of content type application/json; charset=utf-8 VERBOSE: POST https://xx.xx.xxx.xxx/PasswordVault/api/Platforms/xxxxxID/Export with 0-byte payload

Category Info : Not Specified: (:) [Write-Error], WriteErrorException FullyQualifiedErrorId : Microsoft.Powershell.Commands.WriteErrorException,ExportImportPlatform.ps1 Logoff Session... VERBOSE: POST https://xx.xx.xxx.xxx/PasswordVault/api/auth/Logoff with 0-byte payload VERBOSE: received 16-byte response of content type application/json; charset=utf-8

AssafMiron commented 4 years ago

Hello @FanSauChing1996 ,

I see that the first error you received was 'Unauthorized', are you running the script with a "Vault Admin" user permissions? See more details here: https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/ExportPlatform.htm

AssafMiron commented 4 years ago

Any update @FanSauChing1996 ?

Boywunda commented 4 years ago

Hello, I am experiencing the same issue. I am disabling SSLVerify as I was also experiencing the Logon Token being empty. We are running PAS v 10.9. This is my UAT environment, using the actual Administrator account itself.

PS D:\PSScript> ./Import-ConnectionComponents.ps1 -Debug -Verbose -DisableSSLVerify -PVWAURL https://xxx.xxx.xx /PasswordVault -ConnectionComponentZipPath D:\PSScript\TestDSView.zip Import Connection Component: Script Started VERBOSE: POST https://xxx.xxx.xx/PasswordVault/api/auth/cyberark/Logon with -1-byte payload VERBOSE: received 182-byte response of content type application/json; charset=utf-8 VERBOSE: POST https://xxx.xxx.xx/PasswordVault/api/ConnectionComponents/Import with -1-byte payload D:\PSScript\Import-ConnectionComponents.ps1 : Error importing the connection ID, Error: Unauthorized At line:1 char:1

AssafMiron commented 4 years ago

Hello @Boywunda,

I added some Debug messages, mainly in the area of reading the ZIP file I suspect that there was an error in that part where the ZIP file was empty or did not read OK What Powershell version are you running? It would help if you could take the latest version and run it again like you did with the Debug and Verbose switches

Thanks, Assaf

Boywunda commented 4 years ago

Thanks @AssafMiron , I grabbed the newest version, I also generated a new Zip file from the plugin generator and ran it again. This time, it seemed to have worked. The plugin was imported.

A different issue is happening now related to the WebFormSettings of the plugin imported, but that's unrelated to this

Thanks for your assistance!