TsgcWebSocketServer_HTTPAPI › イベント › OnAuthentication
認証が有効になっているときに発生し、アプリケーションがユーザーとパスワードを確認して接続を受け入れるか拒否できます。
property OnAuthentication: TsgcWSAuthenticationEvent;
// TsgcWSAuthenticationEvent = procedure(Connection: TsgcWSConnection; aUser, aPassword: String; var Authenticated: Boolean) of object
—
OnAuthentication は、Authentication.Enabled が True であり、認証方法が組み込みスキーム(Basic、Session、URL)のいずれかである場合、サーバーがクライアントからの認証リクエストを受信するたびに発生します。aUser および aPassword パラメータにはクライアントが提供した認証情報が含まれます。接続を受け入れるには Authenticated を True に、拒否するには False に設定します。認証情報がここで検証されない場合、組み込みの AuthUsers リストがフォールバックとして使用されます。
procedure OnAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string;
var Authenticated: Boolean);
begin
if ((aUser = 'user') and (aPassword = 'secret')) then
Authenticated := True
else
Authenticated := False;
end;