| Total Complexity | 3 |
| Total Lines | 22 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 14 | class CoturnHMAC: |
||
| 15 | def __init__(self, coturn_url=None, coturn_key=None): |
||
| 16 | self.coturn_url = coturn_url or COTURN_URL |
||
| 17 | self.coturn_key = coturn_key or COTURN_KEY |
||
| 18 | |||
| 19 | def fetch_token(self, username='faf-user', ttl=None): |
||
| 20 | ttl = ttl or TWILIO_TTL |
||
| 21 | if ttl is not None: |
||
| 22 | ttl = int(ttl) |
||
| 23 | else: |
||
| 24 | ttl = 3600*24 |
||
| 25 | |||
| 26 | # create hmac of coturn_key + timestamp:username |
||
| 27 | timestamp = int(time.time()) + ttl |
||
| 28 | token_name = "{}:{}".format(timestamp, username) |
||
| 29 | secret = hmac.new(self.coturn_key) |
||
| 30 | hmac.update(token_name) |
||
| 31 | auth_token = base64.b64encode(hmac.digest()) |
||
| 32 | |||
| 33 | return dict(url=self.coturn_url, |
||
| 34 | username=token_name, |
||
| 35 | credential=auth_token) |
||
| 36 | |||
| 39 |