CoTURN: How to use TURN REST API?

前端 未结 6 775
不知归路
不知归路 2020-12-02 18:57

I have build coturn and run it successfully. ip:192.168.1.111. Now the question I faced is to get the Turn credential through REST API. http://tools.ietf.org/html/draft-ube

6条回答
  •  不知归路
    2020-12-02 19:16

    Building upon @Mido and @HeyHeyJC answers, here is the Python implementation to build credentials for coturn.

    import hashlib
    import hmac
    import base64
    from time import time
    
    user = 'your-arbitrary-username'
    secret = 'this-is-the-secret-configured-for-coturn-server'
    
    ttl = 24 * 3600 # Time to live
    timestamp = int(time()) + ttl
    username = str(timestamp) + ':' + user
    dig = hmac.new(secret, username, hashlib.sha1).digest()
    password = base64.b64encode(dig).decode()
    
    print('username: %s' % username)
    print('password: %s' % password)
    

    Here is a web based page to test the login to your coturn server. Use turn:host.example.com as the server name.

提交回复
热议问题