TsgcWebSocket 客户端支持 4 种认证类型:
这是一种简单的授权方法,其中用户名和密码经过编码后作为 HTTP 头传递。只需设置 User 和 Password,并仅启用 Basic 授权类型即可使用此方法。
oClient := TsgcWebSocketClient.Create(nil); oClient.Authentication.Enabled := true; oClient.Authentication.Basic.Enabled := true; oClient.Authentication.User := 'your user'; oClient.Authentication.Password := 'your password'; oClient.Authentication.Token.Enabled := false; oClient.Authentication.URL.Enabled := false; oClient.Authentication.Session.Enabled := false; oClient.Active := True;
允许您使用 JWT 进行授权。这需要您使用外部工具(例如 HTTP 连接、OAuth2 等)获取令牌。
如果附加了 OAuth2 组件,即可自动获取该令牌。阅读更多关于 OAuth2 的内容。
您必须设置 AuthToken 并启用令牌身份验证。
oClient := TsgcWebSocketClient.Create(nil); oClient.Authentication.Enabled := true; oClient.Authentication.Token.Enabled := true; oClient.Authentication.Token.AuthToken := 'your token'; oClient.Authentication.Basic.Enabled := false; oClient.Authentication.URL.Enabled := false; oClient.Authentication.Session.Enabled := false; oClient.Active := True;
客户端首先使用 HTTP 连接连接到服务器,请求一个新的会话。成功后,服务器返回一个 SessionId,客户端在 WebSocket 握手的 GET HTTP 头部中发送该 SessionId。
需要设置 UserName 和 Password 并启用会话身份验证。
oClient := TsgcWebSocketClient.Create(nil); oClient.Authentication.Enabled := true; oClient.Authentication.Session.Enabled := true; oClient.Authentication.User := 'your user'; oClient.Authentication.Password := 'your password'; oClient.Authentication.Basic.Enabled := false; oClient.Authentication.URL.Enabled := false; oClient.Authentication.Token.Enabled := false; oClient.Active := True;
此身份验证方法在 WebSocket 握手的 GET HTTP 请求头中传递用户名和密码。
oClient := TsgcWebSocketClient.Create(nil); oClient.Authentication.Enabled := true; oClient.Authentication.URL.Enabled := true; oClient.Authentication.User := 'your user'; oClient.Authentication.Password := 'your password'; oClient.Authentication.Basic.Enabled := false; oClient.Authentication.Session.Enabled := false; oClient.Authentication.Token.Enabled := false; oClient.Active := True;