oauthwebrtcstunturnrfc5766turnserver

How to configure WebRTC with Coturn and oAuth


I want to use coturn with oAuth. If I understood it correctly I need to do two things:

First point is clear but how do I need to change my WebRTC client to achieve the second point?

Without oAuth I would initialize my RTCPeerConnection like this:

var configuration = {
  'iceServers': [{
    'url': 'turn:turn.example.org',
    'username': 'user',
    'credential': 'password'
  }]
};
var pc = new RTCPeerConnection(configuration)

The WebRTC 1.0 draft defines a RTCIceCredentialType enum so i would think I need to change my configuration like this:

var configuration = {
  'iceServers': [{
    'url': 'turn:turn.example.org',
    'username': 'kid',
    'credential': 'oAuthToken',
    'credentialType': 'token'
  }]
};

Using Wireshark I can't see the ACESS-TOKEN attribute. Any ideas or does anyone know a working example?


Solution

  • It seems like things changed a bit since original question was asked. The webrtc-pc#1033 pull-request alters the spec and introduces the following iceServers configuration syntax:

    var configuration = {
        'iceServers': [{
            "urls": "turns:turn.example.net",
            "username": "username",
            "credential": {
                "macKey": "...",
                "accessToken": "..."
            },
            "credentialType": "oauth"
        }],
        ...
    }
    

    See RTCIceServer documentation page for more configuration examples.