|
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 | +## Fallback (not recommended) |
| 14 | + |
| 15 | +If you need to support older browsers in the short-term, consider loading this library only as a fallback: |
| 16 | + |
| 17 | +```js |
| 18 | +async function register() { |
| 19 | + const parseCreationOptionsFromJSON = |
| 20 | + PublicKeyCredential.parseCreationOptionsFromJSON ?? |
| 21 | + /* @type PublicKeyCredential.parseCreationOptionsFromJSON */ |
| 22 | + (await import("@github/webauthn-json/browser-ponyfill")).parseCreationOptionsFromJSON; |
| 23 | + |
| 24 | + const publicKey = parseCreationOptionsFromJSON({ /* … */ }); |
| 25 | + return navigator.credentials.create({publicKey}); |
| 26 | +} |
| 27 | + |
| 28 | +async function authenticate() { |
| 29 | + const parseRequestOptionsFromJSON = |
| 30 | + PublicKeyCredential.parseRequestOptionsFromJSON ?? |
| 31 | + /* @type PublicKeyCredential.parseRequestOptionsFromJSON */ |
| 32 | + (await import("@github/webauthn-json/browser-ponyfill")).parseRequestOptionsFromJSON; |
| 33 | + |
| 34 | + const publicKey = parseRequestOptionsFromJSON({ /* … */ }); |
| 35 | + return navigator.credentials.get({publicKey}); |
| 36 | +} |
| 37 | +``` |
| 38 | +
|
| 39 | +If you think you need such a fallback, consider testing or instrumenting your code to test if this is really needed for the small percentage of affected users. |
| 40 | +
|
| 41 | +If you have any other authentication methods available, it is likely that your users will still be able to authenticate without this fallback in place. They will also receive the browser-native functionality the next time rheir browser updates. |
| 42 | +
|
| 43 | +<br> |
| 44 | +
|
| 45 | +-------- |
| 46 | +
|
| 47 | +<br> |
| 48 | +
|
| 49 | +This project's old README contents are below: |
| 50 | +
|
| 51 | +<br> |
| 52 | +
|
| 53 | +-------- |
| 54 | +
|
| 55 | +<br> |
6 | 56 |
|
7 | 57 | # `@github/webauthn-json` |
8 | 58 |
|
|
0 commit comments