UWP中的PlayReady许可证检索中的OAuth

时间:2016-12-16 19:06:48

标签: c# uwp drm playready

知道如何将OAuth标头注入PlayReadyLicenseAcquisitionServiceRequest,以便它们包含在BeginServiceRequest()中吗?我无法利用许可URL的查询字符串,或将OAuth令牌嵌入到正文中;它必须位于许可证检索的http请求的标题中。

1 个答案:

答案 0 :(得分:0)

我在这里找到了一些很棒的示例代码:

https://www.eyecatch.no/blog/using-playready-and-smooth-streaming-in-a-windows-10-uwp-app/

但这是下面的魔术酱(加上我的标题):

    public static async Task<bool> RequestLicenseManual(PlayReadyLicenseAcquisitionServiceRequest request, params KeyValuePair<string, object>[] headers)
    {
        Debug.WriteLine("ProtectionManager PlayReady Manual License Request in progress");

        try
        {
            var r = request.GenerateManualEnablingChallenge();

            var content = new ByteArrayContent(r.GetMessageBody());

            foreach (var header in r.MessageHeaders.Where(x => x.Value != null))
            {
                if (header.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase))
                {
                    content.Headers.ContentType = MediaTypeHeaderValue.Parse(header.Value.ToString());
                }
                else
                {
                    content.Headers.Add(header.Key, header.Value.ToString());
                }
            }

            var msg = new HttpRequestMessage(HttpMethod.Post, r.Uri) { Content = content };

            foreach (var header in headers)
            {
                msg.Headers.Add(header.Key, header.Value.ToString());
            }

            Debug.WriteLine("Requesting license from {0} with custom data {1}", msg.RequestUri, await msg.Content.ReadAsStringAsync());

            var client = new HttpClient();
            var response = await client.SendAsync(msg);

            if (response.IsSuccessStatusCode)
            {
                request.ProcessManualEnablingResponse(await response.Content.ReadAsByteArrayAsync());
            }
            else
            {
                Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + await response.Content.ReadAsStringAsync());

                return false;
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + ex.Message);

            return false;
        }

        Debug.WriteLine("ProtectionManager PlayReady License Request successfull");

        return true;
    }