yoke88 / PSPHPIPAM

MIT License
21 stars 18 forks source link

Invalid authentication with New-PhpIpamSession -useAppKeyAuth #15

Closed FPl47h closed 5 years ago

FPl47h commented 5 years ago

hi, I've read several times now the documentation on https://phpipam.net/api/api_documentation/ and unfortunately I miss an example script for creating the session and a post / get call. The docu page probably refers to an outdated Github page "To simplify deployment you can use API classes for different languages ​​available on Github - Collection of API clients for phpipam API." -> https://github.com/yoke88/PSPHPIPAM/tree/4a62b9e7018ca0bf12f3d554e1884ae3eb611440

There are newer versions on the main page: https://github.com/yoke88/PSPHPIPAM. But this brings me the same error message after a small bugfix.

Bugfix on File "New-PhpIpamSession.ps1" in line 57 [ValidateScript ({if ($ PSVersionTable.PSEdition -eq 'Core') {throw (" CrptoAuth need Rijndael256, it's not implemented in powershell core ")})] missing the positive condition so an else {$ true}: [ValidateScript ({if ($ PSVersionTable.PSEdition -eq 'Core') {throw ("CrptoAuth need Rijndael256, it's not implemented in powershell core")} else {$ true}})]

My call:

Import-Module PSPHPIPAM
New-PhpIpamSession -useAppKeyAuth -PhpIpamApiUrl http://server.domain.de/api -appid LocalAPI -appkey 'vidivBkZd5RsEa3VnhlkeVoV7IXDmcdq' -Debug

and my error message about that

New-PhpIpamSession : {"code":401,"success":false,"message":"Unauthorized","time":0.001}
In C:\Users\xxx\Desktop\phpIPam.ps1:3 Zeichen:1
+ New-PhpIpamSession -useAppKeyAuth -PhpIpamApiUrl http://sys-test14.hr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-PhpIpamSession

I use the following Powershell version

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
PSVersion                      5.1.17134.858                                                                                                                                                                                                                     
PSEdition                      Desktop                                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                           
BuildVersion                   10.0.17134.858                                                                                                                                                                                                                    
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                               
SerializationVersion           1.1.0.1  

Can someone tell me if I control the module incorrectly or if there is an error here?

yoke88 commented 5 years ago

which phpipam version do you use? encrypt request will not support in new phpipam version , so the test is mainly on powershell core and you may using -UseStaticAppKeyAuth switch

FPl47h commented 5 years ago

we use the latest version 1.4 I'll try it again soon

username-is-already-taken2 commented 5 years ago

Hi there, Thanks for your scripts, I'm looking to create a PR with some additional functions, in the mean time I haven't been able to get this auth method to work against 1.3.2 of phpipam (-useStaticAppKeyAuth or -useAppKeyAuth)

I get 401 as well. should it work? Also could you comment on how you configured the App within API management? once I know what works I might PR an update to the README. Do you use App security for example?

yoke88 commented 5 years ago

see the updated readme and check the Tests*.ps1 file to see the examples