목표는 클라이언트가 반환한 데이터의 진위성과 무결성을 검증하고, 자격 증명이 예상 사용자에게 바인딩되어 있는지 확인하며, 향후 인증을 위해 공개 키 자격 증명을 안전하게 등록하는 것입니다.
서버는 다음 단계에 따라 클라이언트 응답을 검증해야 합니다:
{
"id": "base64url-encoded credential ID",
"rawId": "base64url-encoded ID bytes",
"response": {
"clientDataJSON": "base64url",
"attestationObject": "base64url"
},
"type": "public-key"
}
클라이언트가 전송한 응답이 유효한 경우 OnWebAuthnRegistrationSuccessful 이벤트가 호출되며, 향후 로그인 검증을 위해 Credential Record를 데이터베이스에 안전하게 저장할 수 있습니다.
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;