sgcWebSockets Authorizations

· Fonctionnalités

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 charge

La bibliothèque prend en charge les principales méthodes d'authentification suivantes:

  1. Authentification par session
  2. Authentification par URL
  3. Authentification basique
  4. OAuth2
  5. JWT (jetons JSON Web)
  6. 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

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

Inconvénients

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.

Avantages

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.

Key Events Avantages


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és

Authentification.TokenParam := srctQuery
Authentification.TokenParam := srctHeader

Components: TsgcHTTP_JWT_Client, TsgcHTTP_JWT_Server

Avantages

6. WebAuthn Authentification

WebAuthn est en fonction du FIDO2 standard et uses cryptographie à clé publique. It enables sans mot de passe.

Components

TsgcWSAPIServer_WebAuthn

Avantages

7. Comparison Table