L'obiettivo è verificare l'autenticità e l'integrità dei dati restituiti dal client, garantire che la credenziale sia associata all'utente previsto e registrare in modo sicuro una credenziale a chiave pubblica per l'autenticazione futura.
Il server deve validare la risposta del client seguendo questi passaggi:
{
"id": "base64url-encoded credential ID",
"rawId": "base64url-encoded ID bytes",
"response": {
"clientDataJSON": "base64url",
"attestationObject": "base64url"
},
"type": "public-key"
}
Se la risposta inviata dal client è valida, l'evento OnWebAuthnRegistrationSuccessful viene chiamato e il Credential Record può essere memorizzato in modo sicuro in un database per le future validazioni di login.
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;
Se si verifica un errore durante la validazione della risposta del client, viene chiamato l'evento OnWebAuthnRegistrationError ed è possibile accedere alla causa dell'errore nel parametro aError.
procedure OnWebAuthnRegistrationError(Sender:
TObject; const aRequest: TsgcWebAuthn_RegistrationVerify_Request; const
aRegistration: TsgcWebAuthn_Registration; const aError: string);
begin
Log('#webauthn_registration_error: ' + aError);
end;