TsgcWebSocket サーバーは 3 種類の認証をサポートしています:
AuthUsersプロパティを使用して、認証済みユーザーのリストを設定できます。次の形式でユーザーを設定するだけです: user=password
サーバーがクライアントから認証リクエストを受信するたびに、このイベントが呼び出されてユーザーが認証されているかどうかを示します。
接続を受け入れるかどうかを指定するには Authenticated パラメータを使用します。
procedure OnAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string;
var Authenticated: Boolean);
begin
if ((aUser = 'user') and (aPassword = 'secret')) then
Authenticated := true
else
Authenticated := false;
end;
JWT など、デフォルトでサポートされていない認証タイプの場合でも、このイベントを使用して接続を受け入れるか拒否するかを決定できます。パラメーターを読み取り、接続を受け入れるかどうかを判断してください。
procedure OnUnknownAuthentication(Connection: TsgcWSConnection; AuthType, AuthData: string;
var aUser, aPassword: string; var Authenticated: Boolean);
begin
if AuthType = 'Bearer' then
begin
if AuthData = 'jwt_token' then
Authenticated := true
else
Authenticated := false;
end
else
Authenticated := false;
end;