Skip to content

Commit 1fbde7c

Browse files
authored
Merge pull request #29 from spottedmahn/owin-4.0
Update Project to Owin 4.0
2 parents cdc5552 + 18d6e82 commit 1fbde7c

File tree

9 files changed

+156
-106
lines changed

9 files changed

+156
-106
lines changed

TaskService/App_Start/OpenIdConnectCachingSecurityTokenProvider.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
using System.Collections.Generic;
2-
using System.Threading.Tasks;
1+
using Microsoft.IdentityModel.Protocols;
2+
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
3+
using Microsoft.IdentityModel.Tokens;
34
using Microsoft.Owin.Security.Jwt;
4-
using System.IdentityModel.Tokens;
5-
using Microsoft.IdentityModel.Protocols;
5+
using System.Collections.Generic;
66
using System.Threading;
7+
using System.Threading.Tasks;
78

89
namespace TaskService.App_Start
910
{
1011
// This class is necessary because the OAuthBearer Middleware does not leverage
1112
// the OpenID Connect metadata endpoint exposed by the STS by default.
12-
public class OpenIdConnectCachingSecurityTokenProvider : IIssuerSecurityTokenProvider
13+
public class OpenIdConnectCachingSecurityTokenProvider : IIssuerSecurityKeyProvider
1314
{
1415
public ConfigurationManager<OpenIdConnectConfiguration> _configManager;
1516
private string _issuer;
16-
private IEnumerable<SecurityToken> _tokens;
17+
private IEnumerable<SecurityKey> _keys;
1718
private readonly string _metadataEndpoint;
1819

1920
private readonly ReaderWriterLockSlim _synclock = new ReaderWriterLockSlim();
2021

2122
public OpenIdConnectCachingSecurityTokenProvider(string metadataEndpoint)
2223
{
2324
_metadataEndpoint = metadataEndpoint;
24-
_configManager = new ConfigurationManager<OpenIdConnectConfiguration>(metadataEndpoint);
25+
_configManager = new ConfigurationManager<OpenIdConnectConfiguration>(metadataEndpoint, new OpenIdConnectConfigurationRetriever());
2526

2627
RetrieveMetadata();
2728
}
@@ -50,20 +51,20 @@ public string Issuer
5051
}
5152

5253
/// <summary>
53-
/// Gets all known security tokens.
54+
/// Gets all known security keys.
5455
/// </summary>
5556
/// <value>
56-
/// All known security tokens.
57+
/// All known security keys.
5758
/// </value>
58-
public IEnumerable<SecurityToken> SecurityTokens
59+
public IEnumerable<SecurityKey> SecurityKeys
5960
{
6061
get
6162
{
6263
RetrieveMetadata();
6364
_synclock.EnterReadLock();
6465
try
6566
{
66-
return _tokens;
67+
return _keys;
6768
}
6869
finally
6970
{
@@ -79,7 +80,7 @@ private void RetrieveMetadata()
7980
{
8081
OpenIdConnectConfiguration config = Task.Run(_configManager.GetConfigurationAsync).Result;
8182
_issuer = config.Issuer;
82-
_tokens = config.SigningTokens;
83+
_keys = config.SigningKeys;
8384
}
8485
finally
8586
{

TaskService/App_Start/Startup.Auth.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Microsoft.Owin.Security.Jwt;
1+
using Microsoft.IdentityModel.Tokens;
2+
using Microsoft.Owin.Security.Jwt;
23
using Microsoft.Owin.Security.OAuth;
34
using Owin;
45
using System;
56
using System.Configuration;
6-
using System.IdentityModel.Tokens;
77
using TaskService.App_Start;
88

99
namespace TaskService

TaskService/TaskService.csproj

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<AppDesignerFolder>Properties</AppDesignerFolder>
1414
<RootNamespace>TaskService</RootNamespace>
1515
<AssemblyName>TaskService</AssemblyName>
16-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
16+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
1717
<MvcBuildViews>false</MvcBuildViews>
1818
<UseIISExpress>true</UseIISExpress>
1919
<IISExpressSSLPort>44332</IISExpressSSLPort>
@@ -24,6 +24,8 @@
2424
<RestorePackages>true</RestorePackages>
2525
<WebGreaseLibPath>..\packages\WebGrease.1.5.2\lib</WebGreaseLibPath>
2626
<UseGlobalApplicationHostFile />
27+
<Use64BitIISExpress />
28+
<TargetFrameworkProfile />
2729
</PropertyGroup>
2830
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2931
<DebugSymbols>true</DebugSymbols>
@@ -44,57 +46,63 @@
4446
</PropertyGroup>
4547
<ItemGroup>
4648
<Reference Include="Microsoft.CSharp" />
47-
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.28, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<SpecificVersion>False</SpecificVersion>
49-
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.202250711\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
49+
<Reference Include="Microsoft.IdentityModel.Logging, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
50+
<HintPath>..\packages\Microsoft.IdentityModel.Logging.5.2.1\lib\net451\Microsoft.IdentityModel.Logging.dll</HintPath>
5051
</Reference>
51-
<Reference Include="Microsoft.Owin">
52-
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
52+
<Reference Include="Microsoft.IdentityModel.Protocols, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
53+
<HintPath>..\packages\Microsoft.IdentityModel.Protocols.5.2.1\lib\net451\Microsoft.IdentityModel.Protocols.dll</HintPath>
5354
</Reference>
54-
<Reference Include="Microsoft.Owin.Host.SystemWeb">
55-
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
55+
<Reference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
56+
<HintPath>..\packages\Microsoft.IdentityModel.Protocols.OpenIdConnect.5.2.1\lib\net451\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll</HintPath>
5657
</Reference>
57-
<Reference Include="Microsoft.Owin.Security">
58-
<HintPath>..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll</HintPath>
58+
<Reference Include="Microsoft.IdentityModel.Tokens, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.5.2.1\lib\net451\Microsoft.IdentityModel.Tokens.dll</HintPath>
5960
</Reference>
60-
<Reference Include="Microsoft.Owin.Security.ActiveDirectory">
61-
<HintPath>..\packages\Microsoft.Owin.Security.ActiveDirectory.3.0.1\lib\net45\Microsoft.Owin.Security.ActiveDirectory.dll</HintPath>
61+
<Reference Include="Microsoft.Owin, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
62+
<HintPath>..\packages\Microsoft.Owin.4.0.0\lib\net451\Microsoft.Owin.dll</HintPath>
6263
</Reference>
63-
<Reference Include="Microsoft.Owin.Security.Jwt">
64-
<HintPath>..\packages\Microsoft.Owin.Security.Jwt.3.0.1\lib\net45\Microsoft.Owin.Security.Jwt.dll</HintPath>
64+
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
65+
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.4.0.0\lib\net451\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
6566
</Reference>
66-
<Reference Include="Microsoft.Owin.Security.OAuth">
67-
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
67+
<Reference Include="Microsoft.Owin.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
68+
<HintPath>..\packages\Microsoft.Owin.Security.4.0.0\lib\net451\Microsoft.Owin.Security.dll</HintPath>
6869
</Reference>
69-
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
70-
<SpecificVersion>False</SpecificVersion>
71-
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
70+
<Reference Include="Microsoft.Owin.Security.ActiveDirectory, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
71+
<HintPath>..\packages\Microsoft.Owin.Security.ActiveDirectory.4.0.0\lib\net451\Microsoft.Owin.Security.ActiveDirectory.dll</HintPath>
72+
</Reference>
73+
<Reference Include="Microsoft.Owin.Security.Jwt, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74+
<HintPath>..\packages\Microsoft.Owin.Security.Jwt.4.0.0\lib\net451\Microsoft.Owin.Security.Jwt.dll</HintPath>
75+
</Reference>
76+
<Reference Include="Microsoft.Owin.Security.OAuth, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77+
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.4.0.0\lib\net451\Microsoft.Owin.Security.OAuth.dll</HintPath>
78+
</Reference>
79+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
80+
<HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
7281
</Reference>
7382
<Reference Include="Owin">
7483
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
7584
</Reference>
7685
<Reference Include="System" />
7786
<Reference Include="System.Data" />
87+
<Reference Include="System.Data.DataSetExtensions" />
7888
<Reference Include="System.Drawing" />
7989
<Reference Include="System.IdentityModel" />
80-
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.2.28, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
81-
<SpecificVersion>False</SpecificVersion>
82-
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.202250711\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
90+
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
91+
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.5.2.1\lib\net451\System.IdentityModel.Tokens.Jwt.dll</HintPath>
8392
</Reference>
8493
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8594
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
8695
<Private>True</Private>
8796
</Reference>
97+
<Reference Include="System.Web.DynamicData" />
8898
<Reference Include="System.Web.Entity" />
8999
<Reference Include="System.Web.ApplicationServices" />
90100
<Reference Include="System.ComponentModel.DataAnnotations" />
91-
<Reference Include="System.Core" />
92-
<Reference Include="System.Data.DataSetExtensions" />
101+
<Reference Include="System.Web.Extensions" />
93102
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
94103
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
95104
<Private>True</Private>
96105
</Reference>
97-
<Reference Include="System.Xml.Linq" />
98106
<Reference Include="System.Web" />
99107
<Reference Include="System.Web.Abstractions" />
100108
<Reference Include="System.Web.Routing" />
@@ -139,6 +147,7 @@
139147
<Private>True</Private>
140148
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
141149
</Reference>
150+
<Reference Include="System.Xml.Linq" />
142151
<Reference Include="WebGrease">
143152
<Private>True</Private>
144153
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
@@ -210,7 +219,9 @@
210219
<Content Include="fonts\glyphicons-halflings-regular.woff" />
211220
<Content Include="fonts\glyphicons-halflings-regular.ttf" />
212221
<Content Include="fonts\glyphicons-halflings-regular.eot" />
213-
<Content Include="packages.config" />
222+
<Content Include="packages.config">
223+
<SubType>Designer</SubType>
224+
</Content>
214225
<None Include="Project_Readme.html" />
215226
</ItemGroup>
216227
<PropertyGroup>

TaskService/Web.config

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@
1616
<add key="ida:Tenant" value="fabrikamb2c.onmicrosoft.com" />
1717
<add key="ida:ClientId" value="90c0fe63-bcf2-44d5-8fb7-b8bbc0b29dc6" />
1818
<add key="ida:SignUpSignInPolicyId" value="b2c_1_susi" />
19-
2019
<!-- The following settings is used for requesting access tokens -->
2120
<add key="api:ReadScope" value="read" />
2221
<add key="api:WriteScope" value="write" />
2322
</appSettings>
23+
<!--
24+
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
25+
26+
The following attributes can be set on the <httpRuntime> tag.
27+
<system.Web>
28+
<httpRuntime targetFramework="4.5.1" />
29+
</system.Web>
30+
-->
2431
<system.web>
25-
<compilation debug="true" targetFramework="4.5" />
32+
<compilation debug="true" targetFramework="4.5.1" />
2633
<httpRuntime targetFramework="4.5" />
2734
</system.web>
28-
2935
<runtime>
3036
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
3137
<dependentAssembly>
3238
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
33-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
39+
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
3440
</dependentAssembly>
3541
<dependentAssembly>
3642
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
@@ -54,7 +60,7 @@
5460
</dependentAssembly>
5561
<dependentAssembly>
5662
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
57-
<bindingRedirect oldVersion="0.0.0.0-4.0.2.28" newVersion="4.0.2.28" />
63+
<bindingRedirect oldVersion="0.0.0.0-5.2.1.0" newVersion="5.2.1.0" />
5864
</dependentAssembly>
5965
<dependentAssembly>
6066
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
@@ -66,7 +72,15 @@
6672
</dependentAssembly>
6773
<dependentAssembly>
6874
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
69-
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
75+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
76+
</dependentAssembly>
77+
<dependentAssembly>
78+
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
79+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
80+
</dependentAssembly>
81+
<dependentAssembly>
82+
<assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31bf3856ad364e35" culture="neutral" />
83+
<bindingRedirect oldVersion="0.0.0.0-5.2.1.0" newVersion="5.2.1.0" />
7084
</dependentAssembly>
7185
</assemblyBinding>
7286
</runtime>

TaskService/packages.config

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.0" targetFramework="net45" />
1313
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net45" />
1414
<package id="Microsoft.AspNet.WebPages" version="3.2.0" targetFramework="net45" />
15-
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.202250711" targetFramework="net45" />
16-
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />
17-
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net45" />
18-
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net45" />
19-
<package id="Microsoft.Owin.Security.ActiveDirectory" version="3.0.1" targetFramework="net45" />
20-
<package id="Microsoft.Owin.Security.Jwt" version="3.0.1" targetFramework="net45" />
21-
<package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net45" />
15+
<package id="Microsoft.IdentityModel.Logging" version="5.2.1" targetFramework="net451" />
16+
<package id="Microsoft.IdentityModel.Protocols" version="5.2.1" targetFramework="net451" />
17+
<package id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="5.2.1" targetFramework="net451" />
18+
<package id="Microsoft.IdentityModel.Tokens" version="5.2.1" targetFramework="net451" />
19+
<package id="Microsoft.Owin" version="4.0.0" targetFramework="net451" />
20+
<package id="Microsoft.Owin.Host.SystemWeb" version="4.0.0" targetFramework="net451" />
21+
<package id="Microsoft.Owin.Security" version="4.0.0" targetFramework="net451" />
22+
<package id="Microsoft.Owin.Security.ActiveDirectory" version="4.0.0" targetFramework="net451" />
23+
<package id="Microsoft.Owin.Security.Jwt" version="4.0.0" targetFramework="net451" />
24+
<package id="Microsoft.Owin.Security.OAuth" version="4.0.0" targetFramework="net451" />
2225
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
2326
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
24-
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
27+
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net451" />
2528
<package id="Owin" version="1.0" targetFramework="net45" />
2629
<package id="Respond" version="1.2.0" targetFramework="net45" />
27-
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.202250711" targetFramework="net45" />
30+
<package id="System.IdentityModel.Tokens.Jwt" version="5.2.1" targetFramework="net451" />
2831
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
2932
</packages>

TaskWebApp/App_Start/Startup.Auth.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Identity.Client;
2-
using Microsoft.IdentityModel.Protocols;
2+
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
3+
using Microsoft.IdentityModel.Tokens;
34
using Microsoft.Owin.Security;
45
using Microsoft.Owin.Security.Cookies;
56
using Microsoft.Owin.Security.Notifications;
@@ -8,7 +9,6 @@
89
using System;
910
using System.Configuration;
1011
using System.IdentityModel.Claims;
11-
using System.IdentityModel.Tokens;
1212
using System.Threading.Tasks;
1313
using System.Web;
1414
using TaskWebApp.Models;
@@ -94,8 +94,8 @@ private Task OnRedirectToIdentityProvider(RedirectToIdentityProviderNotification
9494

9595
if (!string.IsNullOrEmpty(policy) && !policy.Equals(DefaultPolicy))
9696
{
97-
notification.ProtocolMessage.Scope = OpenIdConnectScopes.OpenId;
98-
notification.ProtocolMessage.ResponseType = OpenIdConnectResponseTypes.IdToken;
97+
notification.ProtocolMessage.Scope = OpenIdConnectScope.OpenId;
98+
notification.ProtocolMessage.ResponseType = OpenIdConnectResponseType.IdToken;
9999
notification.ProtocolMessage.IssuerAddress = notification.ProtocolMessage.IssuerAddress.ToLower().Replace(DefaultPolicy.ToLower(), policy.ToLower());
100100
}
101101

0 commit comments

Comments
 (0)