4

I am trying to call a WCF REST service from my windows 8 app and I'm always prompted for the credential. I have Default Windows Credentials activated in the package manifest and am looking for the equivalent of

HttpClientHandler handler = new HttpClientHandler(); 
handler.UseDefaultCredentials = true;

when using javascript.

The service is set up to use windows auth and works fine when called from IE9.

Samarth
  • 69
  • 5
  • Have you found the solution ? I have the same problem .. – KANAX Dec 22 '15 at 10:21
  • Hi KANAX, I never really found a solution for this at the time. If I remember correctly, I had to stop using WinJS for this and move to C# where there was never a problem. Sorry I can't be of any more help, I don't remember the details. – Samarth Feb 16 '16 at 15:44
  • Okay thank you for your response! I'm still searching a solution to this for my part – KANAX Feb 16 '16 at 16:09

1 Answers1

0

You can use Winjs.xhr for the call. Make sure defaultWindowsCredentials are set in appxmanifest (as you said they are).

Sample usage:

WinJS.xhr({
    url: requestUrl, user: 'username', pass: 'password, headers: { accept: 'application/json'}
}).then(
    function (req) {
    var data = JSON.parse(req.response);
    document.getElementById('foo').innerHTML = data.d[0].;
    // Now call the user-supplied callback function when this data is ready
    c({
       results: data.d,
        number: data.d.length
    });
},  //Error func
    function (req) {
    e(req);
}, //progress func
    function (req) {
    p(req);
}
);

You could also user a c# project to take care of WCF communication and have the Javascript project cal it's methods.

Other authetication paths:

The Windows.Security.Authentication.Live "Enables Metro style apps to use Windows Live to authenticate users using their Windows Live ID"

Also take a look at Metro style app for banking: code walkthrough with several authentication scenarios and to Web Authentication.

Live SDK Developer Preview will lso enable you to "Take advantage of single sign-on scenarios using Windows Live ID in Windows Developer Preview".

  • Hi, Thanks a lot! Is there anyway I can get the application to use the current security context instead of prompting the user for credentials ? The C# code works for this but I was looking for a WinJS equivalent. – Samarth Feb 03 '12 at 08:29