how to authenticate coturn with rest api

1,488 views
Skip to first unread message

sara waheed

unread,
Oct 2, 2020, 9:02:39 AM10/2/20
to TURN Server (Open-Source project)
i am running the coturn server in ubuntu on localhost 
here is my turnserver.conf 

    verbose
    listening-ip=127.0.0.1
    realm=test.demo
    static-auth-secret=fb1d5d356dff13e709980e2a07dfcef130a713d53e4c6701efe4b770f27e17d4
    use-auth-secret

starting the server as 

    service coturn start
    service coturn status
returned 

    ● coturn.service - LSB: coturn TURN Server
       Loaded: loaded (/etc/init.d/coturn; generated)
       Active: active (running) since Fri 2020-10-02 17:28:08 PKT; 3s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 18905 ExecStop=/etc/init.d/coturn stop (code=exited, status=0/SUCCESS)
      Process: 18912 ExecStart=/etc/init.d/coturn start (code=exited, status=0/SUCCESS)
        Tasks: 15 (limit: 4915)
       CGroup: /system.slice/coturn.service
               └─18934 /usr/bin/turnserver -c /etc/turnserver.conf -o -v
    
    Oct 02 17:28:08 user-Inspiron-7773 systemd[1]: Starting LSB: coturn TURN Server...
    Oct 02 17:28:08 user-Inspiron-7773 coturn[18912]:  * Starting coturn  turnserver
    Oct 02 17:28:08 user-Inspiron-7773 coturn[18912]:    ...done.
    Oct 02 17:28:08 user-Inspiron-7773 systemd[1]: Started LSB: coturn TURN Server.

and `sudo netstat -npta | grep turnserver` gives 

    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
    tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    


i have generated the temporary username and password 
    
    val secretKey = "fb1d5d356dff13e709980e2a07dfcef130a713d53e4c6701efe4b770f27e17d4"
    val userId= "abcd1234"
    val ttl:Long = 3600 * 6
    val unixTimeStamp =System.currentTimeMillis()/1000L + ttl
    val userName = unixTimeStamp +":"+ userId
    val secret = new SecretKeySpec(secretKey.getBytes, "HmacSHA1")
    val mac = Mac.getInstance("HmacSHA1")
    mac.init(secret)
    val result: Array[Byte] = mac.doFinal(userName.getBytes)
    val hashStr= new String(result.map(_.toChar))
    val password = Base64.getEncoder.encodeToString(hashStr.getBytes())

and it produces the output 
username:1601663142:abcd1234
password: Wi4H776QJCoFbe+/hgrvv7Pvv5te77+m776L776K776N77+Y77+UUQ==

i have tested this in two ways 
first in chrome console following code throws the exception 

    var iceConfiguration = {
        iceServers: [
            {
                urls: 'turn:127.0.0.1:3478',
                username: '1601663142:abcd1234',
                credentials: 'Wi4H776QJCoFbe+/hgrvv7Pvv5te77+m776L776K776N77+Y77+UUQ=='
            }
    
        ]
    }
    
    var peerConnection = new RTCPeerConnection(iceConfiguration);

    Uncaught DOMException: Failed to construct 'RTCPeerConnection': Both username and credential are required when the URL scheme is "turn" or "turns".
        at <anonymous>:12:22
    (anonymous) @ VM41:12

    
 
how can i get it to working 
Screenshot from 2020-10-02 17-57-11.png

Julio Spinelli

unread,
Jul 24, 2021, 1:59:24 PM7/24/21
to TURN Server (Open-Source project)
This question and answers may help you restapi
Reply all
Reply to author
Forward
0 new messages