OpenTok API 身份验证



我正在尝试在我的Angular App中调用OpenTok API。我正在使用以下代码

$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
})

我有一个有效的json_web_token我正在传递。但是,每当我尝试拨打此电话时,我都会收到。

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

我很难弄清楚如何设置自定义 X-OPENTOK-AUTH 标头。谁能告诉我我的代码出了什么问题,或者有没有人有对 OpenTok 进行$http调用的示例?

我把JSON网络令牌弄错了。不得不将其移动到后端并在那里完成所有操作。

这有帮助 https://tokbox.com/blog/author/madhav/

在迈克的回答基础上,问题是这样的:

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

是不正确的。X-OPENTOK-AUTH 应该是标头名称,而不是标头值。授权标头名称将被忽略。它应该看起来像这样:

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

有关 API 参考,请参阅 https://tokbox.com/developer/rest/#authentication,有关该主题的博客文章,请参阅 https://tokbox.com/blog/jwt-the-new-authentication-scheme-for-opentok-rest-endpoints/。

最新更新