Hi Mark,
I just had to google AngularJS because I'd never heard of it, despite being into programming in several languages over the years.
I thought I should be able to give you a reasonable stab at the correct AngularJS code myself, but there seem to be lots of people asking on stackoverflow etc about using credentials with angularjs and not getting too much success.
What we are trying to achieve is communicating with the Indigo web service. I am assuming you've enabled security on it; definitely recommended if you're going to allow remote access to your system for monitoring or control.
For a web server running on a PC/Mac/whatever, there are off the top of my head four authentication methods: None, Basic, Digest and Integrated.
None is self-explanatory.
Integrated is used on Windows business networks where IT Administrators allow their internal web servers to be accessed by anyone who has successfully logged into their business PC - ie they are already an authorised authenticated user, so the webserver automatically trusts the user.
Basic and
Digest are similar to each other - if you use your browser to access a webserver, the browser will prompt you for login details. However Basic passes the response (username/password) in clear text to the webserver, unencrypted, whereas Digest encrypts it using a hash that is negotiated between the browser and the webserver.
Indigo is compiled using Digest by default, as it is more secure - therefore if you are using a scripting language to talk to it, that language must support Digest authentication. It is possible to switch Indigo to Basic, but it's certainly recommended to try it with Digest first.
In my code above, there are four sections.
First, I define my username and password in code, as string values.
Second, I create a credential object from the username/password strings. I believe this could be passed directly to a Basic-authenticated webserver, but we need it to be Digest.
Third, I create/convert the credential into a credential usable for Digest authentication.
Finally, I create a web request and attach my Digest credential to it:
- Code: Select all
$webClient = new-object System.Net.WebClient #Create $webClient (aka your $http)
$webClient.Credentials = $cacheDigestCred #Attach digest credential to the $webClient
$webPage = $webClient.DownloadString($url) #Instruct the $webClient to fetch the $url, which it will do using the credentials we attached to it
This page has a AngularJS question/answer where iwein says:
- Code: Select all
You should pass a configuration object, like so
$http.post(url, {withCredentials: true, ...})
or in older versions:
$http({withCredentials: true, ...}).post(...)
It looks like 'withCredentials' is how you tell your code to USE credentials, but I've found no reference as to how you specify what those are.
Hope that helps?
Peter