通过添加带有“token=tokenvalue”的 URL 查询参数来传递令牌。在 Azure 媒体服务中无法正常工作

问题描述 投票:0回答:1

尝试将视频从 Azure 媒体服务流式传输到 Xamarin.Form 应用程序。 该资产受 JWT 令牌保护。

我使用以下代码来生成令牌:

private string GetJWT(string PrimaryKey) {

 var tokenSigningKey = new SymmetricSecurityKey(Convert.FromBase64String(PrimaryKey));

 SigningCredentials cred = new SigningCredentials(tokenSigningKey, SecurityAlgorithms.HmacSha256);

 JwtSecurityToken token = new JwtSecurityToken(
     issuer: "xxx",
     audience: "yyy",
     claims: null,
     notBefore: DateTime.Now.AddMinutes(-5),
     expires: DateTime.Now.AddMinutes(60),
     signingCredentials: cred);

     JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();

     return handler.WriteToken(token);
}

资产的 URI 如下: https://xxx.streaming.media.azure.net/12222-1565-232323-a5b8-c10e148273ae/Test.ism/manifest(format=m3u8-cmaf,encryption=cbc)

如果我使用 Azure Media Player (https://ampdemo.azureedge.net) 来测试 URI 和 AES 令牌,它可以正常工作。所以我猜token本身没有问题...

文档(https://learn.microsoft.com/en-us/azure/media-services/latest/security-pass-authentication-tokens-how-to#pass-a-token-via-the-addition -of-a-url-query-parameter-with-tokentokenvalue) 表示以下代码应该可以直接通过 url 发送令牌。 我需要像使用 Xamarin.Forms 和 MediaElement 一样执行此操作,我无法在标头请求中发送令牌。所以我需要查询字符串选项...

string armoredAuthToken = System.Web.HttpUtility.UrlEncode(authToken);
string uriWithTokenParameter = string.Format("{0}&token={1}", keyDeliveryServiceUri.AbsoluteUri, armoredAuthToken);
Uri keyDeliveryUrlWithTokenParameter = new Uri(uriWithTokenParameter);

player.Source = keyDeliveryUrlWithTokenParameter;   (player is a MediaElement control)

但视频从未加载。 我认为有一个错误,应该是

{0}?token={1}
而不是
{0}&token={1}
。 但这也不起作用。

如果我使用VLC进行测试https://xxx.streaming.media.azure.net/12222-1565-232323-a5b8-c10e148273ae/Test.ism/manifest(format=m3u8-cmaf,encryption=cbc)?token =zzzzzz,这也不起作用。

我认为查询字符串中的令牌有问题,就好像 Azure 无法读取它一样。

azure-media-services
1个回答
0
投票

可能晚了,FWIW,因为 Azure 媒体服务无论如何都会在 2024 年中期关闭...... 2 个问题:

  1. 您应该将 token=token-value 附加到许可证 URL 的末尾,而不是附加到流 URL 的末尾。
  2. 仍然相关,
    {0}&token={1}
    可以给你指出问题所在。许可证 URL 已包含
    ?
    。例如,licenseURL(如果您查看对以
    manifest(format=m3u8-cmaf,encryption=cbc)
    结尾的流媒体 URL 执行 HTTP GET 的响应,就可以找到它)如下所示:

https://xxx.keydelivery.westeurope.media.azure.net/Widevine/?kid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

© www.soinside.com 2019 - 2024. All rights reserved.