|
| 1 | +project_path: /web/_project.yaml |
| 2 | +book_path: /web/fundamentals/_book.yaml |
| 3 | + |
| 4 | +{# wf_updated_on: 2016-11-08 #} |
| 5 | +{# wf_published_on: 2016-11-08 #} |
| 6 | + |
| 7 | +# The Credential Management API {: .page-title } |
| 8 | + |
| 9 | +{% include "web/_shared/contributors/agektmr.html" %} |
| 10 | +{% include "web/_shared/contributors/megginkearney.html" %} |
| 11 | + |
| 12 | +The [Credential Management API](https://www.w3.org/TR/credential-management/) |
| 13 | +is a standards-based browser API that provides a programmatic interface |
| 14 | +between the site and the browser for seamless sign-in, across devices, and |
| 15 | +removes friction from your sign-in flows. |
| 16 | + |
| 17 | +<div class="attempt-right"> |
| 18 | + <figure> |
| 19 | + <video src="animations/credential-management-smaller.mov" style="max-height: 400px;" autoplay muted loop controls></video> |
| 20 | + <figcaption>User Sign-in Flow</figcaption> |
| 21 | + </figure> |
| 22 | +</div> |
| 23 | + |
| 24 | +The Credential Management API: |
| 25 | + |
| 26 | +* **Makes sign-in flow simple** - Users can automatically signed back into a |
| 27 | + site, even if their session has expired. |
| 28 | +* **Allows one tap sign in with account chooser** - A native account chooser is shown |
| 29 | + eliminating the sign in form. |
| 30 | +* **Stores credentials** - Can store either a username & password combination |
| 31 | + or even federated account details. |
| 32 | + |
| 33 | +Want to see it in action? Try the |
| 34 | +[Credential Management API Demo](https://credential-management-sample.appspot.com) |
| 35 | +and take a look at the |
| 36 | +[code](https://github.com/GoogleChrome/credential-management-sample). |
| 37 | + |
| 38 | +<div class="clearfix"></div> |
| 39 | + |
| 40 | + |
| 41 | +## Steps to implement Credential Management |
| 42 | + |
| 43 | +While there are many ways to successfully integrate the Credential Management |
| 44 | +API, and the specifics of an integration depend on the structure and user |
| 45 | +experience of the site, sites that use this flow have these user experience |
| 46 | +advantages: |
| 47 | + |
| 48 | +* Existing users of your service that have a single credential saved to the |
| 49 | + browser are immediately signed in, and they are redirected to the signed-in |
| 50 | + page as soon as authentication finishes. |
| 51 | +* Users that have multiple credentials saved or that have disabled automatic |
| 52 | + sign-in need to respond to one dialog before they go to the website's |
| 53 | + signed-in page. |
| 54 | +* When users sign out, the website ensures they are not automatically |
| 55 | + signed back in. |
| 56 | + |
| 57 | +Key Point: Using the Credential Management API requires the page be served |
| 58 | +from a secure origin. |
| 59 | + |
| 60 | +### Retrieve user credentials and sign in |
| 61 | + |
| 62 | +To sign the user in, retrieve the credentials from the browser's password |
| 63 | +manager and use those to log the user in. |
| 64 | + |
| 65 | +For example: |
| 66 | + |
| 67 | +1. When a user lands on your site and they are not signed in, |
| 68 | + call `navigator.credential.get()` |
| 69 | +2. Use the retrieved credentials to sign the user in. |
| 70 | +3. Update the UI to indicate the user has been signed in. |
| 71 | + |
| 72 | +Learn more in |
| 73 | +[Retrieve Credentials](/web/fundamentals/security/credential-management/retrieve-credentials). |
| 74 | + |
| 75 | +### Save or update user credentials |
| 76 | + |
| 77 | +If the user signed in with a username and password: |
| 78 | + |
| 79 | +1. After the user successfully signs in, creates an account or changes a |
| 80 | + password, create the `PasswordCredential` with the user ID and |
| 81 | + the password. |
| 82 | +2. Save the credential object using `navigator.credentials.store()`. |
| 83 | + |
| 84 | + |
| 85 | +If the user signed in with a federated identity provider such as Google |
| 86 | +Sign-In, Facebook, GitHub, etc: |
| 87 | + |
| 88 | +1. After the user successfully signs in, creates an account or changes a |
| 89 | + password, create the `FederatedCredential` with the user's email address as |
| 90 | + the ID and specify the identity provider with `.provider` |
| 91 | +2. Save the credential object using `navigator.credentials.store()`. |
| 92 | + |
| 93 | +Learn more in |
| 94 | +[Store Credentials](/web/fundamentals/security/credential-management/store-credentials). |
| 95 | + |
| 96 | +### Sign out |
| 97 | + |
| 98 | +When the user signs out, call `navigator.credentials.requireUserMediation()` |
| 99 | +to prevent the user from being automatically signed back in. |
| 100 | + |
| 101 | +Disabling auto-sign-in also enables users to switch between accounts easily, |
| 102 | +for example, between work and personal accounts, or between accounts on |
| 103 | +shared devices, without having to re-enter their sign-in information. |
| 104 | + |
| 105 | +Learn more in |
| 106 | +[Sign out](/web/fundamentals/security/credential-management/retrieve-credentials#sign-out). |
| 107 | + |
| 108 | + |
| 109 | +## Additional References |
| 110 | + |
| 111 | +[Credential Management API on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Credential_Management_API) |
0 commit comments