TsgcWebSocketHTTPServer › プロパティ › 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 := TsgcWebSocketHTTPServer.Create(nil);
oServer.Authentication.Enabled := true;
oServer.Authentication.Basic.Enabled := true;
oServer.Authentication.AuthUsers.Add('user=secret');
oServer.Active := true;