REST API

301 views
Skip to first unread message

EduIT

unread,
Oct 4, 2017, 11:12:08 AM10/4/17
to pwm-general
Has anyone been able to successfully access the provided REST APIs using Powershell? I've been at it for days, with no success. I seem to be having issues with authentication even though I'm attempting to start off with the /pwm/public/rest/statistics call which I didn't expect would require it. (Please take that last sentence with a grain of salt, as I've been working on this for SO long, that I'm completely turned around!)

I think my server is configured properly - I've checked it at least a dozen times, though I will double check anything requested. The only clue I have is that I can access the statistics API through a browser call, but only on my second consecutive attempt.

Full version info, for those interested: v1.8.0-SNAPSHOT b28700112 r28ded00d08aa0deb05885294681497b1adb0ae81. I've attempted to install the latest and greatest, in case I was running up against a known bug.

If tried every random suggestion I could find with my very best GoogleFu but here is the basis of my code, and what I initially expected to work:

[string]$BaseUri = "http://MyUrl:8080/pwm/public/rest/statistics"
[string]$ContentType = "application/json"

$session=new-object microsoft.powershell.commands.webrequestsession

$Headers = @{'Accept' = 'application/json'; 'Accept-Language' = 'en'; 'Authorization' = 'Basic MyAuthDetails'}

$JSONResponse = Invoke-WebRequest -URI $BaseURI -Headers $Headers -ContentType $ContentType -Method Get -websession $session

Any pointers are greatly appreciated.

EduIT

unread,
Oct 4, 2017, 4:07:59 PM10/4/17
to pwm-general
I can't believe I forgot to include the error message from the logs:

"error while processing PwmValueTag: 5015 ERROR_UNKNOWN (attempt to read PwmSession from HttpSession failed)"

Obviously this is what pushed me to look into authentication options to fix my issues. I simply don't know enough about the technique to get there by myself.

Jason Rivard

unread,
Oct 5, 2017, 12:00:44 AM10/5/17
to pwm-general
Take a look at the very latest build, there has been a substantial re-write of the REST services framework in PWM, particularly around authentication.  For authentication take a look at 'Settings ⇨ Web Services ⇨ REST Services ⇨ External Web Services Secrets', and create a secret user/password there and enable it for all services.

hpal...@clarkson.edu

unread,
Oct 6, 2017, 12:36:15 PM10/6/17
to pwm-general
Thanks Jason,
I took your advice and grabbed the newest build. My upgrade was a disaster so I'm now on a clean install from the 10/4 build.

I'm getting further, which is nice, but I'm still not getting back data - just:

{"error": true,
"errorCode": 7000,
"errorMessage": "Error_RestInvocationError"}

I am using the 'External Web Service Secrets' as you suggested, which I granted every possible permission. I have logging turned way up, but this is all I'm getting:

rest request authentication status: {\"type":"NAMED_SECRET\",\"namedSecretName\":"\MySuperSecretUsername\","usages\":[\"RandomPassword\","\Profile\",\"VerifyResponses\",\"Status\",\"SetPassword\",\"SigningForm\",\"Challenges\",\"CheckPassword\",\"Statistics\",\"VerifyOtp\",\"Health\"],\"thirdPartyEnabled\".true}

And then:

completed rest invocation in 11ms success=false

I have no idea what I'm doing wrong and can't turn the log info into anything helpful. Is what I'm trying to do just not possible?

EduIT

unread,
Oct 9, 2017, 2:57:17 PM10/9/17
to pwm-general
For anyone wandering by and wondering how this resolved itself, running the 10/4/2017 build I was able to successfully read from the REST API by creating an 'External Web Services Secrets' and by sending 'Content-Type' = 'application/x-www-form-urlencoded'

Reply all
Reply to author
Forward
0 new messages