0

I am trying to make a call to the OpenTok API in my Angular App. I am using the following code

 $http({
    method: 'POST',
    url: 'https://api.opentok.com/v2/project/{{apiKey}}/broadcast',
    data: data,
    headers: {
      'Authorization':'X-OPENTOK-AUTH',
      'Content-Type': 'application/json'
    },
    token: json_web_token
  })

I have a valid json_web_token I am passing in. However whenever I try to make this call I get.

{"code":-1,"message":"No suitable authentication found"}

I am having a hard time figuring out how to set the custom X-OPENTOK-AUTH header. Can anyone tell me what is wrong with my code or does anyone have an example of a $http call being made to OpenTok?

Mike F.
  • 21
  • 1
  • 2

2 Answers2

0

I was making the JSON web token wrong. Had to move this to the backend and do it all there.

This helped https://tokbox.com/blog/author/madhav/

Mike F.
  • 21
  • 1
  • 2
0

To build on Mike's answer the problem is this:

'Authorization':'X-OPENTOK-AUTH',

is incorrect. X-OPENTOK-AUTH should be the header name, not the header value. The Authorization header name is ignored. It should look something like:

'X-OPENTOK-AUTH': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMjMiLCJpc3QiOiJwcm9qZWN0IiwiaWF0IjoxNTAyMzMxNDk3LCJleHAiOjE1MDIzMzE3OTd9.WJ1yJkD6IgXofj85Wyjdl80QEumLVBHIgtj-9vAhOZU'

Please see https://tokbox.com/developer/rest/#authentication for the API reference or https://tokbox.com/blog/jwt-the-new-authentication-scheme-for-opentok-rest-endpoints/ for a blog post on the topic.

aiham
  • 3,614
  • 28
  • 32