Le sgcWebSockets bibliothèque prend en charge plusieurs méthodes d'authentification pour sécuriser les communications WebSocket in Delphi et C++Builder applications. Comme le protocole WebSocket ne définit pas lui-même de mécanisme d'authentification, sgcWebSockets implémente son propre ensemble de techniques adapté aux côtés serveur et client.
Types d'authentification pris en chargeLa bibliothèque prend en charge les principales méthodes d'authentification suivantes:
- Authentification par session
- Authentification par URL
- Authentification basique
- OAuth2
- JWT (jetons JSON Web)
- WebAuthn (Web Authentication)
1. Authentification par session
Le client effectue une requête HTTP GET pour recevoir un jeton de session:
http://host:port/sgc/req/auth/session/:user/:password
Le serveur répond avec un jeton, qui est ensuite utilisé dans l'URL WebSocket:
ws://host:port/sgc/auth/session/:token
Propriétés
Authentification.Enabled := True;
Avantages
- L'accès par jeton le rend sûr et simple.
- Adapté aux applications avec un système de connexion.
Exemple
Client.URL := 'ws://localhost:443/sgc/auth/session/your-token';
2. Authentification par URL
Credentials are included directly dans le WebSocket URL:
ws://host:port/sgc/auth/url/username/password
Avantages
- Very simple to implement.
- Compatible avec browser-based WebSocket clients.
Inconvénients
- Credentials are exposed dans le URL.
- Should seulement be used avec SSL/TLS.
3. Authentification basique
Uses le standard HTTP Authorization header:
Authorization: Basic base64(user:password)
Propriétés
Authentification.AuthUsers := 'user=password';
Use le OnAuthentication événement for custom validation.
- Simple et familiar.
- Server manages une liste de valid utilisateurs.
Exemple
procedure WSServerAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string; var Authenticated: Boolean);
begin
if (aUser = 'John') and (aPassword = '1234') then
Authenticated := True;
end;
4. OAuth2 Authentification
OAuth2 est pris en charge through components tel que TsgcHTTP_OAuth2_Server et TsgcHTTP_OAuth2_Client.
It works avec providers like Google, Microsoft, Azure AD, et custom identity systems.
- OnOAuth2Authentification
- OnOAuth2AfterAccessToken
- Modern et secure.
- Well-suited for web applications et cloud environments.
5. JWT Authentification
Authentification est performed utilisant JSON Web Tokens (JWT). Tokens peut être passed either dans le query string ou in HTTP headers.
PropriétésAuthentification.TokenParam := srctQuery
Authentification.TokenParam := srctHeader
Components: TsgcHTTP_JWT_Client, TsgcHTTP_JWT_Server
Avantages- Stateless et scalable.
- Widely adopted, integrates easily avec external services.
6. WebAuthn Authentification
WebAuthn est en fonction du FIDO2 standard et uses cryptographie à clé publique. It enables sans mot de passe.
ComponentsTsgcWSAPIServer_WebAuthn
Avantages- Very strong security.
- Resistant to phishing et credential theft.
7. Comparison Table

