Skip to content

Commit 33ac9c1

Browse files
author
Cagri Yildirim
committed
Update WebAuthenticationRequested.md
Updated event's name to BasicAuthenticationRequest to clarify the scenario for the event.
1 parent 4628619 commit 33ac9c1

1 file changed

Lines changed: 57 additions & 57 deletions

File tree

specs/WebAuthenticationRequested.md

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,50 +21,50 @@
2121

2222

2323
# Background
24-
By default HTTP basic authentication requests inside WebView2 show the authentication UI, which is a dialog prompt in which the user can type in user name and password credentials just like in the Edge browser. We have been requested by WebView2 app developers to provide finer granularity for managing HTTP Basic authentications inside WebView2, including the ability to hide the login UI and provide credentials.
24+
By default HTTP basic authentication and NTLM authentication requests inside WebView2 show the authentication UI, which is a dialog prompt in which the user can type in user name and password credentials just like in the Edge browser. We have been requested by WebView2 app developers to provide finer granularity for managing HTTP Basic/NTLM authentications inside WebView2, including the ability to hide the login UI and provide credentials.
2525

2626

2727
# Description
28-
We propose a new event for WebView2, CoreWebView2WebAuthenticationRequested that will allow developers to listen on and override the HTTP Basic authentication requests in WebView2. When there is a HTTP Basic authentication request in WebView2, the developer will have a choice to:
28+
We propose a new event for WebView2, CoreWebView2BasicAuthenticationRequested that will allow developers to listen on and override the HTTP Basic authentication requests in WebView2. When there is a HTTP Basic/NTLM authentication request in WebView2, the developer will have a choice to:
2929
1) Provide credentials
3030
2) Cancel the login altogether
3131
3) Ask the user for credentials via the default login prompt
32-
We also propose CoreWebView2WebAuthenticationResponse, the runtime class that represents the app's response with credentials to the basic authentication request.
32+
We also propose CoreWebView2BasicAuthenticationResponse, the runtime class that represents the app's response with credentials to the basic authentication request.
3333

3434
# Examples
3535
## Provide credentials
3636
The developer can provide the authentication credentials on behalf of the user when it encounters the Basic authentication request. In this case, the default login dialog prompt will no longer be shown to the user. If the developer provided credentials are wrong, the server may keep responding with Unauthorized, which will lead to an infinite loop so the developer should pay attention to this.
3737

3838
```cpp
3939

40-
webview2->add_WebAuthenticationRequested(
41-
Callback<ICoreWebView2WebAuthenticationRequestedEventHandler>(
40+
webview2->add_BasicAuthenticationRequested(
41+
Callback<ICoreWebView2BasicAuthenticationRequestedEventHandler>(
4242
[this](
4343
ICoreWebView2* sender,
44-
ICoreWebView2WebAuthenticationRequestedEventArgs* args)
44+
ICoreWebView2BasicAuthenticationRequestedEventArgs* args)
4545
{
4646
wil::com_ptr<ICoreWebView2Environment> webviewEnvironment;
4747
m_appWindow->GetWebViewEnvironment()->QueryInterface(
4848
IID_PPV_ARGS(&webviewEnvironment));
4949
wil::com_ptr<ICoreWebView2Deferral> deferral;
50-
wil::com_ptr<ICoreWebView2WebAuthenticationRequestedEventArgs> web_auth_args = args;
50+
wil::com_ptr<ICoreWebView2BasicAuthenticationRequestedEventArgs> web_auth_args = args;
5151
args->GetDeferral(&deferral);
5252
ShowCustomLoginUI().then([web_auth_args, deferral](LPCWSTR userName, LPCWSTR password) {
53-
wil::com_ptr<ICoreWebView2WebAuthenticationResponse> webAuthenticationResponse;
54-
args->get_Response(&webAuthenticationResponse);
55-
webAuthenticationResponse->put_UserName(userName);
56-
webAuthenticationResponse->put_Password(password);
53+
wil::com_ptr<ICoreWebView2BasicAuthenticationResponse> basicAuthenticationResponse;
54+
args->get_Response(&basicAuthenticationResponse);
55+
basicAuthenticationResponse->put_UserName(userName);
56+
basicAuthenticationResponse->put_Password(password);
5757
deferral->Complete();
5858
}
5959
6060
return S_OK;
6161
})
6262
.Get(),
63-
&m_webAuthenticationRequestedToken));
63+
&m_BasicAuthenticationRequestedToken));
6464
```
6565
6666
```c#
67-
webView.CoreWebView2.WebAuthenticationRequested += delegate (object sender, CoreWebView2WebAuthenticationRequestedEventArgs args)
67+
webView.CoreWebView2.BasicAuthenticationRequested += delegate (object sender, CoreWebView2BasicAuthenticationRequestedEventArgs args)
6868
{
6969
CoreWebView2Deferral deferral = args.GetDeferral();
7070
Credential credential = await ShowCustomLoginUIAsync();
@@ -78,36 +78,36 @@ webView.CoreWebView2.WebAuthenticationRequested += delegate (object sender, Core
7878
The developer can block the authentication request. In this case, the default login dialog prompt will no longer be shown to the user and the server will respond as if the user clicked cancel.
7979

8080
```cpp
81-
webview2->add_WebAuthenticationRequested(
82-
Callback<ICoreWebView2WebAuthenticationRequestedEventHandler>(
81+
webview2->add_BasicAuthenticationRequested(
82+
Callback<ICoreWebView2BasicAuthenticationRequestedEventHandler>(
8383
[this](
8484
ICoreWebView2* sender,
85-
ICoreWebView2WebAuthenticationRequestedEventArgs* args)
85+
ICoreWebView2BasicAuthenticationRequestedEventArgs* args)
8686
{
8787
args->put_Cancel(true);
8888

8989
return S_OK;
9090
})
9191
.Get(),
92-
&m_webAuthenticationRequestedToken));
92+
&m_BasicAuthenticationRequestedToken));
9393
```
9494
9595
```c#
96-
webView.CoreWebView2.WebAuthenticationRequested += delegate (object sender, CoreWebView2WebAuthenticationRequestedEventArgs args)
96+
webView.CoreWebView2.BasicAuthenticationRequested += delegate (object sender, CoreWebView2BasicAuthenticationRequestedEventArgs args)
9797
{
9898
args.Cancel = true;
9999
};
100100
```
101101

102-
## Read authorization challenge string
103-
Developer can read the authorization challenge string sent by server. Note that if the developer doesn't cancel or provide a response, the default login dialog prompt will be shown to the user.
102+
## Read authentication challenge string
103+
Developer can read the authentication challenge string sent by server. Note that if the developer doesn't cancel or provide a response, the default login dialog prompt will be shown to the user.
104104

105105
```cpp
106-
webview2->add_WebAuthenticationRequested(
107-
Callback<ICoreWebView2WebAuthenticationRequestedEventHandler>(
106+
webview2->add_BasicAuthenticationRequested(
107+
Callback<ICoreWebView2BasicAuthenticationRequestedEventHandler>(
108108
[this](
109109
ICoreWebView2* sender,
110-
ICoreWebView2WebAuthenticationRequestedEventArgs* args)
110+
ICoreWebView2BasicAuthenticationRequestedEventArgs* args)
111111
{
112112
args->get_Challenge(&challenge);
113113
if (!ValidateChallenge(challenge.get())) { // Check the challenge string
@@ -116,11 +116,11 @@ webview2->add_WebAuthenticationRequested(
116116
return S_OK;
117117
})
118118
.Get(),
119-
&m_webAuthenticationRequestedToken));
119+
&m_BasicAuthenticationRequestedToken));
120120
```
121121
122122
```c#
123-
webView.CoreWebView2.WebAuthenticationRequested += delegate (object sender, CoreWebView2WebAuthenticationRequestedEventArgs args)
123+
webView.CoreWebView2.BasicAuthenticationRequested += delegate (object sender, CoreWebView2BasicAuthenticationRequestedEventArgs args)
124124
{
125125
if (args.Challenge.Equals("Expected login credentials")) {
126126
args.Cancel = true;
@@ -144,66 +144,66 @@ interface ICoreWebView2_4 : ICoreWebView2_3
144144
{
145145
/// ...
146146
147-
/// Add an event handler for the WebAuthenticationRequested event.
148-
/// WebAuthenticationRequested event is raised when WebView encounters a Basic HTTP
147+
/// Add an event handler for the BasicAuthenticationRequested event.
148+
/// BasicAuthenticationRequested event is raised when WebView encounters a Basic HTTP
149149
/// Authentication request as described in
150150
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication.
151151
///
152152
/// The host can provide a response with credentials for the authentication or
153153
/// cancel the request. If the host doesn't set the Cancel property to true or
154154
/// populate the Response property, then WebView2 will show the default
155-
/// authorization challenge dialog prompt to the user.
155+
/// authentication challenge dialog prompt to the user.
156156
///
157-
HRESULT add_WebAuthenticationRequested(
158-
[in] ICoreWebView2WebAuthenticationRequestedEventHandler* eventHandler,
157+
HRESULT add_BasicAuthenticationRequested(
158+
[in] ICoreWebView2BasicAuthenticationRequestedEventHandler* eventHandler,
159159
[out] EventRegistrationToken* token);
160160
/// Remove an event handler previously added with add_WebResourceRequested.
161-
HRESULT remove_WebAuthenticationRequested(
161+
HRESULT remove_BasicAuthenticationRequested(
162162
[in] EventRegistrationToken token);
163163
}
164164
165-
/// This is the CoreWebView2WebAuthenticationRequestedEventHandler interface
165+
/// This is the CoreWebView2BasicAuthenticationRequestedEventHandler interface
166166
[uuid(f87e5d35-3248-406b-81dd-1c36aab8081d), object, pointer_default(unique)]
167-
interface ICoreWebView2WebAuthenticationRequestedEventHandler : IUnknown
167+
interface ICoreWebView2BasicAuthenticationRequestedEventHandler : IUnknown
168168
{
169169
/// Called to provide the implementer with the event args for the
170170
/// corresponding event.
171171
HRESULT Invoke(
172172
[in] ICoreWebView2* sender,
173-
[in] ICoreWebView2WebAuthenticationRequestedEventArgs* args);
173+
[in] ICoreWebView2BasicAuthenticationRequestedEventArgs* args);
174174
}
175175
176176
/// Represents a Basic HTTP authentication response that contains a user name
177177
/// and a password as according to RFC7617 (https://tools.ietf.org/html/rfc7617)
178178
[uuid(bc9cfd60-29c4-4943-a83b-d0d2f3e7df03), object, pointer_default(unique)]
179-
interface ICoreWebView2WebAuthenticationResponse : IUnknown
179+
interface ICoreWebView2BasicAuthenticationResponse : IUnknown
180180
{
181-
/// User name provided for authorization.
181+
/// User name provided for authentication.
182182
[propget] HRESULT UserName([out, retval] LPWSTR* userName);
183183
/// Set user name property
184184
[propput] HRESULT UserName([in] LPCWSTR userName);
185185
186-
/// Password provided for authorization
186+
/// Password provided for authentication
187187
[propget] HRESULT Password([out, retval] LPWSTR* password);
188188
/// Set password property
189189
[propput] HRESULT Password([in] LPCWSTR password);
190190
}
191191
192-
/// Event args for the WebAuthorizationRequested event. Will contain the
193-
/// request that led to the HTTP authorization challenge, the challenge
194-
/// and allows the host to provide authentication response or cancel the request.
192+
/// Event args for the BasicAuthenticationRequested event. Will contain the
193+
/// request that led to the HTTP authentication challenge, the challenge
194+
/// and allows the host to provide credentials response or cancel the request.
195195
[uuid(51d3adaa-159f-4e48-ad39-a86beb2c1435), object, pointer_default(unique)]
196-
interface ICoreWebView2WebAuthenticationRequestedEventArgs : IUnknown
196+
interface ICoreWebView2BasicAuthenticationRequestedEventArgs : IUnknown
197197
{
198-
/// The web resource request that led to the authorization challenge
198+
/// The web resource request that led to the authentication challenge
199199
[propget] HRESULT Request([out, retval] ICoreWebView2WebResourceRequest** request);
200200
201-
/// The authorization challenge string
201+
/// The authentication challenge string
202202
[propget] HRESULT Challenge([out, retval] LPWSTR* challenge);
203203
204204
/// Response to the authentication request with credentials. This object will be populated by the app
205205
/// if the host would like to provide authentication credentials.
206-
[propget] HRESULT Response([out, retval] ICoreWebView2WebAuthenticationResponse** response);
206+
[propget] HRESULT Response([out, retval] ICoreWebView2BasicAuthenticationResponse** response);
207207
208208
/// Cancel the authentication request. False by default.
209209
/// If set to true, Response set will be ignored.
@@ -221,15 +221,15 @@ interface ICoreWebView2WebAuthenticationRequestedEventArgs : IUnknown
221221
```c#
222222
namespace Microsoft.Web.WebView2.Core
223223
{
224-
/// Event args for the WebAuthorizationRequested event. Will contain the
225-
/// request that led to the HTTP authorization challenge, the challenge
224+
/// Event args for the BasicAuthenticationRequested event. Will contain the
225+
/// request that led to the HTTP authentication challenge, the challenge
226226
/// and allows the host to provide authentication response or cancel the request.
227-
runtimeclass CoreWebViewWebAuthenticationRequestedEventArgs
227+
runtimeclass CoreWebViewBasicAuthenticationRequestedEventArgs
228228
{
229-
/// The web resource request that led to the authorization challenge
229+
/// The web resource request that led to the authentication challenge
230230
CoreWebView2WebResourceRequest Request { get; };
231231

232-
/// The HTTP basic authorization challenge string
232+
/// The HTTP basic authentication challenge string
233233
String Challenge { get; };
234234

235235
/// Cancel the authentication request. False by default.
@@ -238,33 +238,33 @@ namespace Microsoft.Web.WebView2.Core
238238

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.
241-
CoreWebView2WebAuthenticationResponse Response { get; };
241+
CoreWebView2BasicAuthenticationResponse Response { get; };
242242
}
243243

244244
/// Represents a Basic HTTP authentication response that contains a user name
245245
/// and a password as according to RFC7617 (https://tools.ietf.org/html/rfc7617)
246-
runtimeclass CoreWebView2WebAuthenticationResponse
246+
runtimeclass CoreWebView2BasicAuthenticationResponse
247247
{
248-
/// User name provided for authorization.
248+
/// User name provided for authentication.
249249
String UserName { get; set; }
250250

251-
/// Password provided for authorization
251+
/// Password provided for authentication
252252
String Password { get; set; };
253253
}
254254

255255
runtimeclass CoreWebView2
256256
{
257257
...
258258

259-
/// Add an event handler for the WebAuthenticationRequested event.
260-
/// WebAuthenticationRequested event is raised when WebView encountered a Basic HTTP
259+
/// Add an event handler for the BasicAuthenticationRequested event.
260+
/// BasicAuthenticationRequested event is raised when WebView encountered a Basic HTTP
261261
/// Authentication request.
262262
///
263263
/// The host can populate the response object with credentials it wants to use for the authentication or
264264
/// cancel the request. If the host doesn't handle the event, WebView will show
265-
/// the authorization challenge dialog prompt to user.
265+
/// the authentication challenge dialog prompt to user.
266266
///
267-
event Windows.Foundation.TypedEventHandler<CoreWebView2, CoreWebViewWebAuthenticationRequestedEventArgs> WebAuthenticationRequested;
267+
event Windows.Foundation.TypedEventHandler<CoreWebView2, CoreWebViewBasicAuthenticationRequestedEventArgs> BasicAuthenticationRequested;
268268
}
269269
}
270270
```

0 commit comments

Comments
 (0)