The sgcWebSockets libreria supporta multiple autenticazione metodi a secure WebSocket communication in Delphi e C++Builder applications. Poiché il WebSocket protocol itself non define an autenticazione mechanism, sgcWebSockets implementa il suo own impostare di techniques suitable per entrambi server e client sides.
Supported Autenticazione TypesThe libreria supporta il seguente principale autenticazione methods:
- Session Autenticazione
- URL Autenticazione
- Basic Autenticazione
- OAuth2
- JWT (JSON Web Tokens)
- WebAuthn (Web Autenticazione)
1. Session Autenticazione
The client performs an HTTP GET richiesta a ricevere a session token:
http://host:port/sgc/req/auth/session/:user/:password
The server responds con a token, che è poi utilizzato in il WebSocket URL:
ws://host:port/sgc/auth/session/:token
Properties
Authentication.Enabled := True;
Advantages
- Token-based access rende it secure e simple.
- Suitable per applicazioni con a login system.
Example
Client.URL := 'ws://localhost:443/sgc/auth/session/your-token';
2. URL Autenticazione
Credentials sono included directly in il WebSocket URL:
ws://host:port/sgc/auth/url/username/password
Advantages
- Molto simple a implement.
- Compatible con browser-based WebSocket clients.
Disadvantages
- Credentials sono exposed in il URL.
- Dovrebbe solo essere utilizzato con SSL/TLS.
3. Basic Autenticazione
Uses il standard HTTP Authorization header:
Authorization: Basic base64(user:password)
Properties
Authentication.AuthUsers := 'user=password';
Use il OnAuthentication evento per custom validation.
- Simple e familiar.
- Server manages a list di valido users.
Example
procedure WSServerAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string; var Authenticated: Boolean);
begin
se (aUser = 'John') e (aPassword = '1234') then
Authenticated := True;
end;
4. OAuth2 Autenticazione
OAuth2 è supportati attraverso componenti come TsgcHTTP_OAuth2_Server e TsgcHTTP_OAuth2_Client.
It works con providers like Google, Microsoft, Azure AD, e custom identity systems.
- OnOAuth2Authentication
- OnOAuth2AfterAccessToken
- Modern e secure.
- Well-suited per web applicazioni e cloud environments.
5. JWT Autenticazione
Authentication è performed utilizzando JSON Web Tokens (JWT). Tokens può essere passed sia in il query string o in HTTP headers.
PropertiesAuthentication.TokenParam := srctQuery
Autenticazione.TokenParam := srctHeader
Components: TsgcHTTP_JWT_Client, TsgcHTTP_JWT_Server
Advantages- Stateless e scalable.
- Widely adopted, integrates easily con external services.
6. WebAuthn Autenticazione
WebAuthn è based su il FIDO2 standard e utilizza public chiave cryptography. It abilita passwordless authentication.
ComponentsTsgcWSAPIServer_WebAuthn
Advantages- Molto strong security.
- Resistant a phishing e credential theft.
7. Comparison Table

