How to transfer current Windows credentials to WCF REST service from native Windows 8 application executed using JS?

I am trying to call the WCF REST service from my Windows 8 application and I am always prompted for credentials. I have default Windows credentials activated in the package manifest and I'm looking for an equivalent

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

when using javascript.

The service is configured to use windows auth and works great when called from IE9.

+4
source share
1 answer

You can use Winjs.xhr to call. Make sure defaultWindowsCredentials are set to 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 can also use a C # project to take care of WCF communication and use a Javascript project.

Other ways of autoterization:

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 the Metro style banking app: code walkthrough with multiple authentication scenarios and Web authentication .

The Live SDK Developer Preview allows you to "use single sign-on scripts using the Windows Live ID in the Windows Developer Preview."

0
source

Source: https://habr.com/ru/post/1392010/


All Articles