エラーメッセージ
NotAllowedError: The operation either timed out or was not allowed. See: https://www.w3.org/TR/webauthn-2/#sctn-privacy-considerations-client.
別の表記
- NotAllowedError: The operation either timed out or was not allowed.
- NotAllowedError: CredentialsContainer request is not allowed.
上記は Chromium のテキストです(古いバージョンには「See: …」のリンクがありません)。Firefox は「CredentialsContainer request is not allowed.」と表示します(認証器のないヘッドレス版 Firefox 157 で再現)。メッセージはブラウザーごとに異なり、変わらないのは `e.name` だけです。
WebAuthn navigator.credentials.get() / create() — DOMException NotAllowedError (Chromium; Firefox wording in aliases)
このエラーの意味
ブラウザーが返す、WebAuthn の包括的なエラーです。仕様は「ユーザーがキャンセルした」「タイムアウト時間が経過した」「一致する認証情報を持つ認証器がない」「このコンテキストではリクエストが許可されていない」を、Web ページからは意図的に区別できないようにしています。デバイスにどの認証情報があるかをサイトが探れないようにするためです(理由はリンク先のプライバシーに関するセクションで説明されています)。そのため、コードではこのエラーを「認証情報が作成されなかった」として扱い、別の手段を提示しなければなりません。本当の原因は、エラーを読むのではなく、再現することで突き止めます。
発生する理由
allowCredentials のどの認証情報もこの認証器にない
よくあるアカウントのパスキーが別のデバイスにあるか、削除されたか、別の RP ID で登録されています。ブラウザーはタイムアウトまで一致する認証器を待ち、その後で NotAllowedError を報告します。
ユーザーがダイアログを閉じた、またはタイムアウトした
よくあるブラウザーのパスキー画面を閉じた場合も、生体情報による検証に何度も失敗した場合も、時間のかかるセキュリティキーの操作に対して `timeout` が短すぎた場合も、結果は同じです。
ユーザー操作なしで、または非表示のページから呼び出された
ときどき特に Safari では、`create()`/`get()` をクリックへの応答として実行しなければなりません。時間のかかるネットワークリクエストを `await` した後に呼び出すと、ユーザーアクティベーションが失われることがあります。バックグラウンドのタブや、`publickey-credentials-*` の権限がないクロスオリジンの iframe でも失敗します。
pubKeyCredParams に対応しているアルゴリズムがない
ときどき列挙した COSE アルゴリズムのどれにも認証器が対応していない場合、登録は失敗し、個別のエラーではなく NotAllowedError が返されます。
修正方法
- 1.
「認証情報なし」として扱い、代替手段を提示する
不安をあおるようなエラーは表示しないでください。別のログイン方法、別のデバイス(ハイブリッド/QR フロー)、新しいパスキーの登録を提示してください。
js try { const credential = await navigator.credentials.get({ publicKey: options }); await finishLogin(credential); } catch (e) { if (e.name === "NotAllowedError") { // Cancelled, timed out, or no passkey for this account on this device: offer alternatives. showOtherSignInOptions(); } else { throw e; } } - 2.
登録時に一般的なアルゴリズムを列挙する
ES256、EdDSA、RS256 を列挙すれば、事実上すべての認証器をカバーできます。その場合、サーバーは 3 つのアルゴリズムすべての署名を検証できなければなりません。
js // Registration: offer the algorithms authenticators actually support. pubKeyCredParams: [ { type: "public-key", alg: -7 }, // ES256 { type: "public-key", alg: -8 }, // EdDSA (Ed25519) { type: "public-key", alg: -257 }, // RS256 (Windows Hello and older security keys) ],
関連するエラー
SecurityError: The relying party ID is not a registrable domain suffix of, nor…WebAuthn navigator.credentials.create() / get()InvalidStateError: The user attempted to register an authenticator that contain…WebAuthn navigator.credentials.create() with excludeCredentialsUnexpected registration response origin "http://localhost:3000", expected "http…SimpleWebAuthn (@simplewebauthn/server)