Serwer TURN | Długoterminowe dane uwierzytelniające

Serwery TURN są zazwyczaj konfigurowane Z uwierzytelnianiem dla żądań TURN i bez uwierzytelniania dla żądań STUN.

 

Serwer sgcWebSockets TURN obsługuje długoterminowe poświadczenia, więc można skonfigurować TsgcTURNServer tak, aby zezwalał jedynie na żądania z informacjami o długoterminowych poświadczeniach.

 

Aby skonfigurować, należy uzyskać dostęp do właściwości TURNOptions.Authorization i ją włączyć.

Następnie należy uzyskać dostęp do właściwości LongTermCredentials i włączyć ją. Domyślnie ten typ autoryzacji jest już skonfigurowany z ciągiem Realm oraz domyślną wartością StaleNonce wynoszącą 10 minut (= 600 sekund).

 


oTURN := TsgcTURNServer.Create(nil);
oTURN.Port := 3478;
oTURN.STUNOptions.Authentication.Enabled := False;
oTURN.TURNOptions.Authentication.Enabled := True;
oTURN.TURNOptions.Authentication.LongTermCredentials.Enabled := True;
oTURN.TURNOptions.Authentication.LongTermCredentials.Realm := 'sgcWebSockets';
oTURN.TURNOptions.Authentication.LongTermCredentials.StaleNonce := 600;
oTURN.Active := True;

procedure OnSTUNRequestAuthorization(Sender: TObject; const aRequest: TsgcSTUN_Message; 
  const aUsername, aRealm: string; var Password: string);
begin
  if (aUsername = 'my-user') and (aRealm = 'sgcWebSockets') then
    Password := 'my-password';
end;