| Conditions | 3 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 19 | def fetch_token(self, username='faf-user', ttl=None): |
||
| 20 | servers = [] |
||
| 21 | |||
| 22 | ttl = ttl or TWILIO_TTL |
||
| 23 | if ttl is not None: |
||
| 24 | ttl = int(ttl) |
||
| 25 | else: |
||
| 26 | ttl = 3600*24 |
||
| 27 | |||
| 28 | |||
| 29 | # create hmac of coturn_key + timestamp:username |
||
| 30 | timestamp = int(time.time()) + ttl |
||
| 31 | token_name = "{}:{}".format(timestamp, username) |
||
| 32 | |||
| 33 | for coturn_url, coturn_key in zip(self.coturn_urls, self.coturn_keys): |
||
| 34 | secret = hmac.new(coturn_key) |
||
| 35 | hmac.update(token_name) |
||
| 36 | auth_token = base64.b64encode(hmac.digest()) |
||
| 37 | |||
| 38 | server.append(dict(url=coturn_url, |
||
| 39 | username=token_name, |
||
| 40 | credential=auth_token)) |
||
| 41 | |||
| 42 | return servers |
||
| 43 |