TsgcWebSocketServer_HTTPAPI › プロパティ › Authentication
受信するWebSocketおよびHTTP要求に対して、ユーザー/パスワード認証を有効にして設定します。
property Authentication: TsgcWSAuthenticationServer_Options read FAuthentication write SetAuthentication;
Enabled=False
Authentication.EnabledがTrueの場合、サーバーはすべての受信接続をAuthUsersリスト(1行につきuser=password形式)に対して認証します。3つの組み込みスキームがサポートされています。Session(クライアントがまずHTTP GETを実行してセッションIDを受け取り、次にIDをパラメータとして渡してWebSocketを開く)、URL(ユーザー名とパスワードがWebSocketハンドシェイクのクエリ文字列で送信される)、Basic(HTTP Basic Access Authentication、VCLクライアント/サーバーとHTTPリクエストにのみ使用)。OnAuthenticationイベントで独自の認証チェックを追加できます。OnUnknownAuthenticationはBearer/JWTなどの非標準スキームを処理します。CustomHeadersを使用して認証エラー時に返す追加のHTTPヘッダーを追加できます。
oServer := TsgcWebSocketServer_HTTPAPI.Create(nil);
oServer.Authentication.Enabled := true;
oServer.Authentication.Basic.Enabled := true;
oServer.Authentication.AuthUsers.Add('user=secret');
oServer.Active := true;