目標は、クライアントから返されたデータの信頼性と整合性を確認し、クレデンシャルが期待されるユーザーにバインドされていることを確認し、将来の認証のために公開鍵クレデンシャルを安全に登録することです。
サーバーは、以下の手順に従ってクライアントの応答を検証する必要があります:
{
"id": "base64url-encoded credential ID",
"rawId": "base64url-encoded ID bytes",
"response": {
"clientDataJSON": "base64url",
"attestationObject": "base64url"
},
"type": "public-key"
}
クライアントが送信した応答が有効な場合、OnWebAuthnRegistrationSuccessful イベントが呼び出され、資格情報レコードは将来のログイン検証のためにデータベースに安全に保存できます。
procedure OnWebAuthnRegistrationSuccessful(Sender: TObject; const aRegistration: TsgcWebAuthn_Registration;
const aCredentialRecord: TsgcWebAuthn_CredentialRecord; var Accept: Boolean);
begin
// store in a db
DB.Credentials.Append;
DB.Credentials.FieldByName('Credentials').AsString := aCredentialRecord.AsJSON;
DB.Credentials.Post;
end;
クライアントレスポンスの検証中にエラーが発生した場合、OnWebAuthnRegistrationError イベントが呼び出され、aError パラメータでエラーの理由にアクセスできます。
procedure OnWebAuthnRegistrationError(Sender:
TObject; const aRequest: TsgcWebAuthn_RegistrationVerify_Request; const
aRegistration: TsgcWebAuthn_Registration; const aError: string);
begin
Log('#webauthn_registration_error: ' + aError);
end;