TsgcWebSocketHTTPServer › 事件 › OnUnknownAuthentication
当启用身份验证且服务器无法识别身份验证方法时触发。
property OnUnknownAuthentication: TsgcWSUnknownAuthenticationEvent;
// TsgcWSUnknownAuthenticationEvent = procedure(Connection: TsgcWSConnection; AuthType, AuthData: String; var aUser, aPassword: String; var Authenticated: Boolean) of object
—
当客户端提供的 Authorization 头部与内置方案(Basic、Session、URL)不匹配时,触发 OnUnknownAuthentication 事件,例如 JWT Bearer 令牌或自定义方案。AuthType 参数包含方案名称,AuthData 包含客户端发送的原始凭据;应用程序可解析它们,填充 aUser 和 aPassword 输出参数(以便会话被标记为用户名),最后将 Authenticated 设置为 True 以接受连接,或设置为 False 以拒绝。当 Authentication.Enabled 为 True 时,适用于 WebSocket 升级和 HTTP 请求。
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;