TsgcWSAPIKeyManagerEvents › OnKeyValidated

OnKeyValidated Event

Fired every time ValidateKey completes; carries the key, an aValid flag and the reason.

Syntax

property OnKeyValidated: TsgcAPIKeyOnKeyValidated;
// TsgcAPIKeyOnKeyValidated = procedure(Sender: TObject; const aKey: string; aValid: Boolean; const aReason: string) of object

Default Value

Remarks

Fires synchronously at the end of every ValidateKey call (including the ValidateKey that IsRequestAuthorized runs internally). aValid is the final Boolean answer after all checks; aReason is a machine-readable code such as "ok", "unknown", "revoked", "expired", "scope_missing", "ip_not_allowed", "https_required" or a custom string returned from OnValidation. Use it to feed metrics dashboards and to drive rate-based fraud detection (too many "unknown" rejections from one IP = brute-force). The event is read-only; to override the decision use OnValidation instead.

Example

procedure TForm1.sgcWSAPIKeyManager1KeyValidated(Sender: TObject;
  const aKey: string; aValid: Boolean; const aReason: string);
begin
  if not aValid then
    Inc(FFailureCounters[aReason]);
end;

Back to Events