TsgcWebSocketHTTPServerEvents › OnAuthentication

OnAuthentication Event

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

Syntax

public event TsgcWSAuthenticationEventHandler OnAuthentication;
// delegate void TsgcWSAuthenticationEventHandler(TsgcWSConnection Connection, string aUser, string aPassword, out bool Authenticated)

Default Value

Remarks

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.

Example


void OnAuthentication(TsgcWSConnection Connection, string aUser, string aPassword,
  ref bool Authenticated)
{
  if ((aUser == "user") && (aPassword == "secret"))
    Authenticated = true;
  else
    Authenticated = false;
}

Back to Events