TsgcHTTP_JWT_ServerEvents › OnJWTAfterValidateToken

OnJWTAfterValidateToken Event

Fired after the signature and claim validations run; inspect Header, Payload and Error, and flip the Valid flag to accept or reject the token.

Syntax

property OnJWTAfterValidateToken: TsgcHTTPJWTAfterValidateTokenEvent;
// TsgcHTTPJWTAfterValidateTokenEvent = procedure(Sender: TObject; aConnection: TsgcWSConnection; aToken, aHeader, aPayload, aError: string; var Valid: Boolean) of object

Default Value

Unassigned — the built-in Valid result (signature + claim validations) is returned as-is.

Remarks

Last event of the validation pipeline. Fires after the signature has been verified and the JWTOptions.Validations claim checks have run, regardless of outcome. Parameters:

Example


procedure TMyForm.sgcJWTAfterValidateToken(Sender: TObject;
  aConnection: TsgcWSConnection; aToken, aHeader, aPayload, aError: string;
  var Valid: Boolean);
var
  oJSON: TsgcJSON;
begin
  if not Valid then Exit;
  // extra business check: Issuer must be our auth server
  oJSON := TsgcJSON.Create(nil);
  try
    oJSON.Read(aPayload);
    Valid := (oJSON.Node['iss'] <> nil) and
             (oJSON.Node['iss'].Value = 'https://auth.example.com');
  finally
    oJSON.Free;
  end;
end;

Back to Events