Di solito i server STUN sono configurati senza autenticazione, quindi qualsiasi client STUN può inviare una richiesta di binding e aspettarsi una risposta dal server senza autenticazione.
Il server STUN di sgcWebSockets supporta le credenziali a lungo termine, quindi è possibile configurare TsgcSTUNServer per consentire solo richieste di binding con informazioni sulle credenziali a lungo termine.
Per configurarlo, acceda alla proprietà STUNOptions.Authorization e la abiliti.
Quindi acceda alla proprietà LongTermCredentials e la abiliti. Per impostazione predefinita, questo tipo di autorizzazione è già configurato con una stringa Realm e con un valore StaleNonce predefinito di 10 minuti (= 600 secondi).
oSTUN := TsgcSTUNServer.Create(nil);
oSTUN.Port := 3478;
oSTUN.STUNOptions.Authentication.Enabled := True;
oSTUN.STUNOptions.Authentication.LongTermCredentials.Enabled := True;
oSTUN.STUNOptions.Authentication.LongTermCredentials.Realm := 'sgcWebSockets';
oSTUN.STUNOptions.Authentication.LongTermCredentials.StaleNonce := 600;
oSTUN.Active := True;
procedure OnSTUNRequestAuthorization(Sender: TObject; const aRequest: TsgcSTUN_Message;
const aUsername, aRealm: string; var Password: string);
begin
if aUsername = 'my-user' then
Password := 'my-password';
end;