TsgcWebSocketHTTPServer › Events › OnAuthentication
Fires when authentication is enabled so the application can check user and password and accept or reject the connection.
property OnAuthentication: TsgcWSAuthenticationEvent;
// TsgcWSAuthenticationEvent = procedure(Connection: TsgcWSConnection; aUser, aPassword: String; var Authenticated: Boolean) of object
—
OnAuthentication is raised every time the server receives an authentication request from a 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 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. The event applies to both WebSocket upgrades and plain HTTP requests.
procedure OnAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string;
var Authenticated: Boolean);
begin
if ((aUser = 'user') and (aPassword = 'secret')) then
Authenticated := True
else
Authenticated := False;
end;