@@ -43,15 +43,13 @@ The developer can provide the authentication credentials on behalf of the user w
4343 ICoreWebView2* sender,
4444 ICoreWebView2BasicAuthenticationRequestedEventArgs* args)
4545 {
46- wil::com_ptr<ICoreWebView2Environment> webviewEnvironment;
47- m_appWindow->GetWebViewEnvironment()->QueryInterface(
48- IID_PPV_ARGS(&webviewEnvironment));
4946 wil::com_ptr<ICoreWebView2Deferral> deferral;
5047 wil::com_ptr<ICoreWebView2BasicAuthenticationRequestedEventArgs> web_auth_args = args;
5148 args->GetDeferral(&deferral);
52- ShowCustomLoginUI().then([web_auth_args, deferral](LPCWSTR userName, LPCWSTR password) {
49+ ShowCustomLoginUI().then([web_auth_args, deferral](LPCWSTR userName, LPCWSTR password)
50+ {
5351 wil::com_ptr<ICoreWebView2BasicAuthenticationResponse> basicAuthenticationResponse;
54- args ->get_Response(&basicAuthenticationResponse);
52+ web_auth_args ->get_Response(&basicAuthenticationResponse);
5553 basicAuthenticationResponse->put_UserName(userName);
5654 basicAuthenticationResponse->put_Password(password);
5755 deferral->Complete();
@@ -110,7 +108,8 @@ webview2->add_BasicAuthenticationRequested(
110108 ICoreWebView2BasicAuthenticationRequestedEventArgs* args)
111109 {
112110 args->get_Challenge(&challenge);
113- if (!ValidateChallenge(challenge.get())) { // Check the challenge string
111+ if (!ValidateChallenge(challenge.get()))
112+ { // Check the challenge string
114113 args->put_Cancel(true);
115114 }
116115 return S_OK;
@@ -122,7 +121,8 @@ webview2->add_BasicAuthenticationRequested(
122121```c#
123122webView.CoreWebView2.BasicAuthenticationRequested += delegate (object sender, CoreWebView2BasicAuthenticationRequestedEventArgs args)
124123{
125- if (args.Challenge.Equals("Expected login credentials")) {
124+ if (ValidateChallenge(args.Challenge))
125+ {
126126 args.Cancel = true;
127127 }
128128};
@@ -211,8 +211,8 @@ interface ICoreWebView2BasicAuthenticationRequestedEventArgs : IUnknown
211211 /// Set the Cancel property.
212212 [propput] HRESULT Cancel([in] BOOL cancel);
213213
214- /// Returns an `ICoreWebView2Deferral` object. Use this operation to
215- /// complete the event at a later time .
214+ /// Returns an `ICoreWebView2Deferral` object. Use this deferral to
215+ /// defer the decision to show the Basic Authentication dialog .
216216 HRESULT GetDeferral([out, retval] ICoreWebView2Deferral** deferral);
217217}
218218
@@ -239,6 +239,10 @@ namespace Microsoft.Web.WebView2.Core
239239 /// Response to the authentication request with credentials. This object will be populated by the app
240240 /// if the host would like to provide authentication credentials.
241241 CoreWebView2BasicAuthenticationResponse Response { get ; };
242+
243+ /// Returns an `ICoreWebView2Deferral` object. Use this deferral to
244+ /// defer the decision to show the Basic Authentication dialog.
245+ CoreWebView2Deferral Deferral { get ; };
242246 }
243247
244248 /// Represents a Basic HTTP authentication response that contains a user name
0 commit comments