Skip to content

Commit 826f673

Browse files
committed
Updated to use Json Web Keys support which is part of Azure Media Services .NET SDK 3.3.0.0 release
1 parent 4897987 commit 826f673

11 files changed

Lines changed: 47 additions & 72 deletions

MediaLibraryWebApp/Controllers/MediaLibraryController.cs

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@
1919
using System.IdentityModel.Tokens;
2020
using System.Linq;
2121
using System.Security.Cryptography;
22-
using System.Security.Cryptography.X509Certificates;
2322
using System.Threading.Tasks;
23+
using System.Web;
2424
using System.Web.Mvc;
25-
using System.Xml;
26-
using System.Xml.XPath;
2725
using MediaLibraryWebApp.Models;
26+
using MediaLibraryWebApp.Utils;
27+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
28+
using Microsoft.Owin;
29+
using Microsoft.Owin.Security.OpenIdConnect;
2830
using Microsoft.WindowsAzure.MediaServices.Client;
2931
using Microsoft.WindowsAzure.MediaServices.Client.ContentKeyAuthorization;
3032
using Microsoft.WindowsAzure.MediaServices.Client.DynamicEncryption;
3133
using WebGrease.Css.Extensions;
32-
using System.Web;
33-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
34-
using MediaLibraryWebApp.Utils;
35-
using Microsoft.Owin;
36-
using Microsoft.Owin.Security.OpenIdConnect;
3734
using AuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext;
3835

3936
namespace MediaLibraryWebApp.Controllers
@@ -237,12 +234,13 @@ public IContentKey AddAuthorizationPolicyToContentKey(string assetID, CloudMedia
237234

238235
List<ContentKeyAuthorizationPolicyRestriction> restrictions = new List<ContentKeyAuthorizationPolicyRestriction>();
239236

240-
List<X509Certificate2> certs = GetX509Certificate2FromADMetadataEndpoint();
237+
241238

242239
TokenRestrictionTemplate template = new TokenRestrictionTemplate();
243240
template.TokenType = TokenType.JWT;
244-
template.PrimaryVerificationKey = new X509CertTokenVerificationKey(certs[0]);
245-
certs.GetRange(1, certs.Count - 1).ForEach(c => template.AlternateVerificationKeys.Add(new X509CertTokenVerificationKey(c)));
241+
//Using Active Directory Open ID discovery spec to use Json Web Keys during token verification
242+
template.OpenIdConnectDiscoveryDocument = new OpenIdConnectDiscoveryDocument("https://login.windows.net/common/.well-known/openid-configuration");
243+
246244

247245

248246
//Ignore Empty claims
@@ -287,7 +285,7 @@ private JwtSecurityToken GetJwtSecurityToken()
287285
string userObjectID = owinContext.Authentication.User.Claims.First(c => c.Type == Configuration.ClaimsObjectidentifier).Value;
288286
NaiveSessionCache cache = new NaiveSessionCache(userObjectID);
289287
AuthenticationContext authContext = new AuthenticationContext(Configuration.Authority, cache);
290-
TokenCacheItem kdAPITokenCache = authContext.TokenCache.ReadItems().Where(c => c.Resource == MediaLibraryWebApp.Configuration.KdResourceId).FirstOrDefault();
288+
TokenCacheItem kdAPITokenCache = authContext.TokenCache.ReadItems().Where(c => c.Resource == Configuration.KdResourceId).FirstOrDefault();
291289

292290
if (kdAPITokenCache == null)
293291
{
@@ -314,32 +312,6 @@ private JwtSecurityToken GetJwtSecurityToken()
314312

315313
}
316314

317-
private static List<X509Certificate2> GetX509Certificate2FromADMetadataEndpoint()
318-
{
319-
List<X509Certificate2> certs = new List<X509Certificate2>();
320-
XPathDocument xmlReader = new XPathDocument(Configuration.MetadataUri);
321-
XPathNavigator navigator = xmlReader.CreateNavigator();
322-
XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
323-
manager.AddNamespace("", "urn:oasis:names:tc:SAML:2.0:metadata");
324-
manager.AddNamespace("ns1", "urn:oasis:names:tc:SAML:2.0:metadata");
325-
manager.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
326-
manager.PushScope();
327-
328-
//Reading all certs since AD periodically do cert rollover
329-
XPathNodeIterator nodes =
330-
navigator.Select(
331-
"//ns1:EntityDescriptor/ns1:RoleDescriptor/ns1:KeyDescriptor[@use='signing']/ds:KeyInfo/ds:X509Data/ds:X509Certificate",
332-
manager);
333-
while (nodes.MoveNext())
334-
{
335-
XPathNavigator nodesNavigator = nodes.Current;
336-
//Cert body is base64 encoded in metadata doc
337-
certs.Add(new X509Certificate2(Convert.FromBase64String(nodesNavigator.InnerXml)));
338-
}
339-
340-
341-
return certs;
342-
}
343315

344316

345317
static public IContentKey CreateEnvelopeTypeContentKey(IAsset asset,CloudMediaContext context)

MediaLibraryWebApp/MediaLibraryWebApp.csproj

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@
6262
<SpecificVersion>False</SpecificVersion>
6363
<HintPath>..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
6464
</Reference>
65-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<SpecificVersion>False</SpecificVersion>
67-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.15.204151539\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
65+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66+
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.16.204221202\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
67+
<Private>True</Private>
6868
</Reference>
69-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70-
<SpecificVersion>False</SpecificVersion>
71-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.15.204151539\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
69+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70+
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.16.204221202\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
71+
<Private>True</Private>
7272
</Reference>
73-
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.28, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74-
<SpecificVersion>False</SpecificVersion>
75-
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.202250711\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
73+
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.31, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74+
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.205111437\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
75+
<Private>True</Private>
7676
</Reference>
7777
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7878
<SpecificVersion>False</SpecificVersion>
@@ -102,7 +102,7 @@
102102
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.1.0\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
103103
</Reference>
104104
<Reference Include="Microsoft.WindowsAzure.MediaServices.Client">
105-
<HintPath>..\packages\windowsazure.mediaservices.3.2.0.0\lib\net45\Microsoft.WindowsAzure.MediaServices.Client.dll</HintPath>
105+
<HintPath>..\packages\windowsazure.mediaservices.3.3.0.0\lib\net45\Microsoft.WindowsAzure.MediaServices.Client.dll</HintPath>
106106
</Reference>
107107
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
108108
<SpecificVersion>False</SpecificVersion>
@@ -121,9 +121,9 @@
121121
<Reference Include="System.Data.Services.Client" />
122122
<Reference Include="System.Drawing" />
123123
<Reference Include="System.IdentityModel" />
124-
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.2.28, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
125-
<SpecificVersion>False</SpecificVersion>
126-
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.202250711\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
124+
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20511.1437, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
125+
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.205111437\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
126+
<Private>True</Private>
127127
</Reference>
128128
<Reference Include="System.Runtime.Serialization" />
129129
<Reference Include="System.Security" />
@@ -237,9 +237,9 @@
237237
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
238238
<Content Include="Scripts\bootstrap.js" />
239239
<Content Include="Scripts\bootstrap.min.js" />
240-
<None Include="Scripts\jquery-2.1.3.intellisense.js" />
241-
<Content Include="Scripts\jquery-2.1.3.js" />
242-
<Content Include="Scripts\jquery-2.1.3.min.js" />
240+
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
241+
<Content Include="Scripts\jquery-2.1.4.js" />
242+
<Content Include="Scripts\jquery-2.1.4.min.js" />
243243
<Content Include="Scripts\modernizr-2.6.2.js" />
244244
<Content Include="Scripts\modernizr-2.8.3.js" />
245245
<Content Include="Scripts\npm.js" />
@@ -267,7 +267,7 @@
267267
<Content Include="Views\Shared\_LoginPartial.cshtml" />
268268
<Content Include="Views\MediaLibrary\Index.cshtml" />
269269
<Content Include="Views\UserProfile\Index.cshtml" />
270-
<Content Include="Scripts\jquery-2.1.3.min.map" />
270+
<Content Include="Scripts\jquery-2.1.4.min.map" />
271271
<None Include="Web.Test.config">
272272
<DependentUpon>Web.config</DependentUpon>
273273
</None>
0 Bytes
Binary file not shown.

MediaLibraryWebApp/Scripts/jquery-2.1.3.min.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

MediaLibraryWebApp/Scripts/jquery-2.1.3.min.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

MediaLibraryWebApp/Scripts/jquery-2.1.3.intellisense.js renamed to MediaLibraryWebApp/Scripts/jquery-2.1.4.intellisense.js

File renamed without changes.

MediaLibraryWebApp/Scripts/jquery-2.1.3.js renamed to MediaLibraryWebApp/Scripts/jquery-2.1.4.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery JavaScript Library v2.1.3
2+
* jQuery JavaScript Library v2.1.4
33
* http://jquery.com/
44
*
55
* Includes Sizzle.js
@@ -9,7 +9,7 @@
99
* Released under the MIT license
1010
* http://jquery.org/license
1111
*
12-
* Date: 2014-12-18T15:11Z
12+
* Date: 2015-04-28T16:01Z
1313
*/
1414

1515
(function( global, factory ) {
@@ -67,7 +67,7 @@ var
6767
// Use the correct document accordingly with window argument (sandbox)
6868
document = window.document,
6969

70-
version = "2.1.3",
70+
version = "2.1.4",
7171

7272
// Define a local copy of jQuery
7373
jQuery = function( selector, context ) {
@@ -531,7 +531,12 @@ jQuery.each("Boolean Number String Function Array Date RegExp Object Error".spli
531531
});
532532

533533
function isArraylike( obj ) {
534-
var length = obj.length,
534+
535+
// Support: iOS 8.2 (not reproducible in simulator)
536+
// `in` check used to prevent JIT error (gh-2145)
537+
// hasOwn isn't used here due to false negatives
538+
// regarding Nodelist length in IE
539+
var length = "length" in obj && obj.length,
535540
type = jQuery.type( obj );
536541

537542
if ( type === "function" || jQuery.isWindow( obj ) ) {

MediaLibraryWebApp/Scripts/jquery-2.1.4.min.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MediaLibraryWebApp/Scripts/jquery-2.1.4.min.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MediaLibraryWebApp/Views/MediaLibrary/Index.cshtml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
{
4242
<div class="bs-callout bs-callout-info"><h4>Admin access</h4><p>As member of Admin Group you need to specify which video will be displayed for which user group. Look into profile page to see ObjectIDs of user group. In ClaimType textbox put value as 'group' and in claimValue put ObjectID of AD Group. Only users belonging to this group will be able to obtain content key to decrypt video. </p></div>
4343

44-
<div class="bs-callout bs-callout-warning"><h4>Signing Keys and Azure AD certificates rollover</h4><p>For following example Azure Media Services stores copy of Azure Active Directory signing certificates in order to validate JWT token signature. After Azure Active Directory signing cretificate rotation it is up to application to implement logic to update sertificates within Azure Media Services content key auth policies. Read more about Azure AD certificates rollover at http://technet.microsoft.com/en-us/library/jj933264.aspx </p></div>
45-
46-
4744
using (Html.BeginForm("CleanAllPermissions", "MediaLibrary"))
4845
{
4946
@Html.ActionLink("Clear All Content Keys, Auth and Delivery Policies", "CleanAllPermissions", "MediaLibrary", null, new { @class = "saveButton btn btn-primary", onclick = "return false;" })

0 commit comments

Comments
 (0)