Any idea how to inject OAuth headers into PlayReadyLicenseAcquisitionServiceRequest so they are included with the BeginServiceRequest()? I can't leverage the license URL's query string, or embed the OAuth token in the body; it has to be in the header of the License retrieval's http request.
Asked
Active
Viewed 204 times
0
-
Can you tell me which version of OAuth you are using? – Mike Ma Dec 19 '16 at 05:19
-
@MikeMa. It's OAuth 1.0, and I have the header already prepared but I just can't figure out how to inject it into the license request. Unless there's a whole different approach to OAuth I'm missing.. – Sean Dec 19 '16 at 13:47
1 Answers
0
I found some great sample code here:
https://www.eyecatch.no/blog/using-playready-and-smooth-streaming-in-a-windows-10-uwp-app/
but this was the magic sauce below (with my header addition):
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;
}

Sean
- 2,531
- 2
- 17
- 17