TsgcWebSocket 서버는 3가지 유형의 인증을 지원합니다:
AuthUsers 속성을 사용하여 인증된 사용자 목록을 설정할 수 있습니다. 다음 형식으로 사용자를 설정하기만 하면 됩니다: user=password
서버가 클라이언트로부터 Authentication Request를 수신할 때마다, 이 이벤트가 호출되어 사용자가 인증되었는지 여부를 나타냅니다.
연결을 수락할지 여부를 결정하려면 Authenticated 매개변수를 사용하십시오.
void OnAuthentication(TsgcWSConnection *Connection, string aUser, string aPassword,
ref bool Authenticated)
{
if ((aUser == "user") && (aPassword == "secret"))
{
Authenticated = true;
}
else
{
Authenticated = false;
}
}
기본적으로 지원되지 않는 인증 유형(예: JWT)이라도, 이 이벤트를 사용하여 연결을 수락하거나 거부할 수 있습니다. 매개변수를 읽고 연결을 수락할지 결정하기만 하면 됩니다.
void OnUnknownAuthentication(TsgcWSConnection *Connection, string AuthType, string AuthData,
ref string aUser, ref string aPassword, ref bool Authenticated)
{
if (AuthType == "Bearer")
{
if (AuthData == "jwt_token")
{
Authenticated = true;
}
else
{
Authenticated = false;
}
}
else
{
Authenticated = false;
}
}