我设置了一个简单的 Azure 函数来测试 Azure 媒体服务。我正在尝试保护我上传的视频,但我似乎无法正确获取 JWT。这是简单的功能代码。
[FunctionName("Test")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
var expires = DateTimeOffset.UtcNow.AddMinutes(20);
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("RYhzAnz....VP0uQ==")); // removed full key for brevity
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var claims = new List<Claim>
{
};
var token = new JwtSecurityToken("http://test.net/",
"urn:user",
claims.AsEnumerable(),
expires: expires.LocalDateTime,
signingCredentials: credentials
);
return new OkObjectResult(new JwtSecurityTokenHandler().WriteToken(token));
}
我已在 token 中填写了颁发者/受众,以便它与我的 Azure 设置中的内容相匹配。
我什至在 jwt.io 上验证了该 token ,并且验证正确
但是当我在 Azure Media Player 上测试它时,响应是带有 AuthorizationPolicyEvaluationFailure 的 401。
这是来自 Azure key 传送服务的响应
{
"Error": {
"Message": "Failed content key policy evaluation.",
"Code": "AuthorizationPolicyEvaluationFailure"
}
}
最佳答案
我认为您忘记将内容 key ID 放入声明中。您的政策可能要求这样做。这是生成 token 之前要添加的行:
claims.Add(new Claim(ContentKeyPolicyTokenClaim.ContentKeyIdentifierClaim.ClaimType, keyIdentifier));
关于azure - JWT token 验证正确,但 Azure 媒体 AES 失败,并出现 AuthorizationPolicyEvaluationFailure 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59142571/