TsgcWebSocketServer_HTTPAPIイベント › OnAuthentication

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;

イベントに戻る