TsgcWebSocketServer | Server Authentication

TsgcWebSocket 서버는 3가지 유형의 인증을 지원합니다:

 

 

AuthUsers 속성을 사용하여 인증된 사용자 목록을 설정할 수 있습니다. 다음 형식으로 사용자를 설정하기만 하면 됩니다: user=password

OnAuthentication

서버가 클라이언트로부터 Authentication Request를 수신할 때마다, 이 이벤트가 호출되어 사용자가 인증되었는지 여부를 나타냅니다.

연결을 수락할지 여부를 결정하려면 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;

 

 

OnUnknownAuthentication

기본적으로 지원되지 않는 인증 유형(예: 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;