providing domain/user credentials to webview control

后端 未结 2 882
情歌与酒
情歌与酒 2021-01-06 08:46

Does anyone know how to provide credentials to a WebView control (or even better - run a Windows 8 Metro style application / WinRT app in the context of a specific domain us

相关标签:
2条回答
  • 2021-01-06 09:30

    I have came across same problem, but luckily found an answer :) Main problem in here is that Windows store applications contain 2 diffrent HttpClient's

    One of them is "classic" one we know from c# apps (used automatically) and the other one is "new" HttpClient - which is connected with WebView :)

    Bellow are both types : System.Net.Http.HttpClient ( classic one ) Windows.Web.Http.HttpClient ( new one )

    So remember to declare the new One and do something like the code bellow

    var filter = new HttpBaseProtocolFilter();    
    filter.ServerCredential = new Windows.Security.Credentials.PasswordCredential("http://website","login", "password");
                Windows.Web.Http.HttpClient client2 = new Windows.Web.Http.HttpClient(filter);
                var response = await client2.GetAsync(new Uri("http://website"));
     WebView.Source = new Uri("http://website");
    

    Now remember to change login and password to credentials you want to use, and a website is a site you want to authenticate to.

    It is important to get the response from server - this will make user authenticated @ server so next time you go with webView to that site you will be authenticated

    It works fine with basic authentication and NTLM authentication

    In this cae scenario remember to have enterpriseAuthentication turned off

    Hope it will help people searching for solution of this problem :)

    0 讨论(0)
  • 2021-01-06 09:39

    In order to connect to sites on your corporate network you must enable the privateNetworkClientServer capability in your Package.appxmanifest. You can do this in the XML or you can double-click on the file in Visual Studio and use the designer (capabilities tab). In the UI it's called "Home or Work Networking".

    Now that you have access to the intranet you can navigate to the site but you will be prompted to provide credentials. If you want the users domain identity to automatically be supplied (enterprise single sign on) you need to enable the enterpriseAuthentication capability as well. This is called "Enterprise Authentication" in the manifest UI.

    From there you should be able to browse to any intranet site using a WebView and not have to authenticate. If you are looking to do things outside of the WebView, you should check out the following articles and samples:

    Using WebAuthenticationBroker:

    http://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

    WebAuthenticationBroker has an option called UseCorporateNetwork. Make sure to use that when following along in the sample above.

    Finally, if you want to do Single Sign On with other sites like Facebook or Flicr, see this sample:

    http://msdn.microsoft.com/en-US/library/windows/apps/xaml/Hh465283

    0 讨论(0)
提交回复
热议问题