TsgcWebSocketProxyServerEvents › OnAuthentication

OnAuthentication Event

Fires when authentication is enabled so the application can check user and password and accept or reject the downstream client connection.

Syntax

property OnAuthentication: TsgcWSAuthenticationEvent;
// TsgcWSAuthenticationEvent = procedure(Connection: TsgcWSConnection; aUser, aPassword: String; var Authenticated: Boolean) of object

Default Value

Remarks

OnAuthentication is raised every time the proxy server receives an authentication request from a downstream client, provided Authentication.Enabled is True and the authentication method is one of the built-in schemes (Basic, Session, URL). The aUser and aPassword parameters carry the credentials supplied by the client; set Authenticated to True to accept the connection (so the proxy opens the upstream TCP session on its behalf) or to False to reject it. When the credentials are not validated here the built-in AuthUsers list is used as the fallback. For custom schemes not recognized by the component (for example JWT Bearer tokens) use OnUnknownAuthentication instead.

Example


procedure OnAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string;
  var Authenticated: Boolean);
begin
  if ((aUser = 'user') and (aPassword = 'secret')) then
    Authenticated := True
  else
    Authenticated := False;
end;

Back to Events