Skip to content

Commit 5a42cab

Browse files
[All hosts](security) Enable automatic saving of passwords in webview2 (#5080)
* draft article for webview2 saving passwords * minor edit * Apply suggestions from code review Co-authored-by: Alex Jerabek <[email protected]> * Apply suggestions from code review Co-authored-by: Alex Jerabek <[email protected]> --------- Co-authored-by: Alex Jerabek <[email protected]>
1 parent cf4e69f commit 5a42cab

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

docs/develop/auth-save-passwords.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Automatically save passwords in Microsoft Edge WebView2
3+
description: Learn how to enable WebView2 to save passwords when users sign in using your add-in.
4+
ms.localizationpriority: medium
5+
ms.date: 03/10/2025
6+
---
7+
8+
# Enable automatic password saving in Microsoft Edge WebView2
9+
10+
Most browsers can automatically save passwords on behalf of the user when they sign in. This helps users manage passwords in a secure environment. Microsoft Edge WebView2 also supports automatic password saving. When your add-in is loaded in Microsoft Office on Windows, Webview2 hosts your add-in. To enable automatic password saving, add HTML input controls for the username and password, as shown in the following HTML.
11+
12+
```html
13+
<div>
14+
<label for="username">Username:</label><br/>
15+
<input type="text" id="username" name="username" /><br/>
16+
17+
<label for="password">Password:</label><br/>
18+
<input type="password" id="password" name="password" /><br/>
19+
20+
<button id="btn" type="button">Sign in</button>
21+
</div>
22+
```
23+
24+
In the button click event handler for the sign-in button, call the authentication library of your choice to sign in the user. Once the sign-in is complete, redirect to a new web page. When WebView2 sees the redirect, and the username and password, it prompts the user to offer to automatically save the credentials. The following code shows how to handle the sign-in button click event.
25+
26+
```javascript
27+
async function btnSignIn() {
28+
// Get the username and password credentials entered by the user.
29+
const username = document.getElementById("username").value;
30+
const pwd = document.getElementById("password").value;
31+
32+
try {
33+
// Sign in the user. This is a placeholder for the actual sign-in logic.
34+
await signInUser(username, pwd);
35+
36+
// Redirect to a success page to trigger the password autosave.
37+
window.location.href = "/home.html";
38+
}
39+
catch (error) {
40+
console.error("Sign in failed: " + error);
41+
return;
42+
}
43+
}
44+
```
45+
46+
## How the user manages passwords
47+
48+
When the user enters a new password in your add-in, and your add-in redirects to a new web page, WebView2 asks the user if they want to save their username and password. The next time your add-in prompts for credentials, WebView2 automatically enters the user's account information.
49+
50+
:::image type="content" source="../images/edge-webview2-automatic-save-passwords.png" alt-text="The dialog from WebView2 prompting the user if they want to save their username and password.":::
51+
52+
Users remove saved passwords by deleting The WebView2 local cache folder at `%LOCALAPPDATA%\Microsoft\Office\16.0\Wef\webview2\`. If your add-in relies on automatically saving passwords, you should document this folder location so users can remove their passwords.
53+
54+
## Related content
55+
56+
- [Microsoft Edge WebView2](https://developer.microsoft.com/microsoft-edge/webview2)
57+
- [Browsers and webview controls used by Office Add-ins](../concepts/browsers-used-by-office-web-add-ins.md)
20.9 KB
Loading

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ items:
185185
href: develop/auth-external-add-ins.md
186186
- name: Access Microsoft Graph
187187
href: develop/authorize-to-microsoft-graph-without-sso.md
188+
- name: Automatically save passwords in WebView2
189+
href: develop/auto-save-passwords-in-webview2.md
188190
- name: UI and UX
189191
items:
190192
- name: Overview

0 commit comments

Comments
 (0)