|
1 | | -⚠️ ⚠️ ⚠️ |
| 1 | +# ⚠️ `@github/webauthn-json` is deprecated |
2 | 2 |
|
3 | | -WebAuthn-json has been sunset. Now that [all major browsers support WebAuthn](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API#browser_compatibility) we recommend invoking the native APIs |
| 3 | +As of March 2025, stable versions of all major browsers now support the following methods: |
4 | 4 |
|
5 | | -⚠️ ⚠️ ⚠️ |
| 5 | +- [`PublicKeyCredential.parseCreationOptionsFromJSON(…)`](https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/parseCreationOptionsFromJSON_static) |
| 6 | +- [`PublicKeyCredential.parseRequestOptionsFromJSON(…)`](https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/parseCreationOptionsFromJSON_static) |
| 7 | + |
| 8 | +By design, these are compatible with `@github/webauthn-json` encoding, so you can use them as a drop-in substitute. We strongly recommend doing so, since: |
| 9 | + |
| 10 | +- The browser-native JSON parsing functions are increasingly receiving fields and features (such as user-agent hints and the `prf` extension) that `@github/webauthn-json` will never receive. |
| 11 | +- Removing `@github/webauthn-json` from your codebase will remove code from your authentication pages, reducing load times for your users and reducing the chance you will need to debug issues. |
| 12 | + |
| 13 | +If you need to support older browsers in the short-term, consider loading this library only as a fallback: |
| 14 | + |
| 15 | +```js |
| 16 | +async function register() { |
| 17 | + const parseCreationOptionsFromJSON = |
| 18 | + PublicKeyCredential.parseCreationOptionsFromJSON ?? |
| 19 | + /* @type PublicKeyCredential.parseCreationOptionsFromJSON */ |
| 20 | + (await import("@github/webauthn-json/browser-ponyfill")).parseCreationOptionsFromJSON; |
| 21 | + |
| 22 | + const publicKey = parseCreationOptionsFromJSON({ /* … */ }); |
| 23 | + return navigator.credentials.create({publicKey}); |
| 24 | +} |
| 25 | + |
| 26 | +async function authenticate() { |
| 27 | + const parseRequestOptionsFromJSON = |
| 28 | + PublicKeyCredential.parseRequestOptionsFromJSON ?? |
| 29 | + /* @type PublicKeyCredential.parseRequestOptionsFromJSON */ |
| 30 | + (await import("@github/webauthn-json/browser-ponyfill")).parseRequestOptionsFromJSON; |
| 31 | + |
| 32 | + const publicKey = parseRequestOptionsFromJSON({ /* … */ }); |
| 33 | + return navigator.credentials.get({publicKey}); |
| 34 | +} |
| 35 | +``` |
| 36 | +
|
| 37 | +<br> |
| 38 | +<br> |
| 39 | +
|
| 40 | +This project's old README contents are below: |
| 41 | +
|
| 42 | +<br> |
| 43 | +
|
| 44 | +-------- |
6 | 45 |
|
7 | 46 | # `@github/webauthn-json` |
8 | 47 |
|
|
0 commit comments