TsgcTURNServer › 事件 › OnSTUNRequestAuthorization
当收到已认证请求时触发;请提供与传入 Username/Realm 关联的密码。
property OnSTUNRequestAuthorization: TsgcSTUNRequestAuthorizationEvent;
// TsgcSTUNRequestAuthorizationEvent = procedure(Sender: TObject; const aRequest: TsgcSTUN_Message; const aUsername, aRealm: string; var Password: string) of object
—
针对每个经过身份验证的 STUN 绑定请求和每个 TURN 方法(ALLOCATE、REFRESH、CREATE-PERMISSION、CHANNEL-BIND、Send-Indication),在传入的 MESSAGE-INTEGRITY 属性已解析但尚未验证时触发。aUsername 和 aRealm 从请求中解码;对于 TURN 长期凭据,realm 与 TURNOptions.Authentication.LongTermCredentials.Realm 匹配。将与该用户关联的密码赋值给 Password 变量参数;服务器随后计算 HMAC 密钥,若计算出的完整性值不匹配,则接受请求或返回 401 Unauthorized 响应。将 Password 留为空字符串将拒绝该用户,同样返回 401 响应。此处理程序在监听器线程上运行,除非 NotifyEvents 选择了其他模式,请保持其简短且线程安全。
procedure TForm1.OnSTUNRequestAuthorization(Sender: TObject;
const aRequest: TsgcSTUN_Message; const aUsername, aRealm: string;
var Password: string);
begin
if (aUsername = 'user') and (aRealm = 'esegece.com') then
Password := 'password'
else
Password := '';
end;