- March 3, 2016 at 7:49 am #35990
I have created an internal Web API and written Powershell modules to interact with it.
Some of the actions in the Web API needs authorization.
Hence, in Powershell I need to do something like this:
Invoke-WebRequest $url -Method Get -ContentType "application/json" -Credential (Get-Credential)
But the user is already opening the powershell prompt with their own user, and that should be enough to get authorized.
I guess I am looking for a feature like in Internet Explorer, where I can add a internal website as a Intranet site, therefor it won't ask for extra credentials.
Hope it makes sence.March 3, 2016 at 7:56 am #35993
That is, as you suggest, a feature of IE – not a general feature of Windows. IE is doing some malarky under the hood – receiving an authentication prompt from the web server, and then responding to it with a security token. You'd have to build that functionality yourself, and it ain't gonna be easy. Invoke-WebRequest is a much lower-level creature, and doesn't do any of the fancy stuff a browser does – like track cookies, automatically respond to auth requests, etc. It's just sending data back and forth.March 3, 2016 at 8:03 am #35995
Thank you for your answer. I guess I will then make it so that the module will just prompt the user one time and then reuse it within that session.
StigMarch 3, 2016 at 8:03 am #35996
Instead of -Credential, you'd just use the -UseDefaultCredentials switch on Invoke-WebRequest. This is assuming that your website uses Windows Authentication. If it's HTTP auth or forms-based or whatever, then you can't use the user's existing credentials without them re-entering the password.March 3, 2016 at 8:08 am #35997
@dlwyatt – Thank you very much. Was exactly what I was looking for. Don't know how I missed the -UseDefaultCredentials parameter. I am using Windows Authentication – sorry for not making that clear in the first place.
StigMarch 3, 2016 at 8:15 am #35998
Oh, apologies – I wasn't thinking that's what you were after. Sorry. Thanks Dave.March 3, 2016 at 8:17 am #36000
No problem 🙂
You must be logged in to reply to this topic.