Skip to content

Commit 0a57985

Browse files
authored
In AddTokenAcquisition(singleton:true) an implementation of TokenAcquirerFactory (for ASP.NET Core 2.x on .NET FW) (#2850)
1 parent 2c1414b commit 0a57985

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/Microsoft.Identity.Web.TokenAcquisition/ServiceCollectionExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static IServiceCollection AddTokenAcquisition(
7878
services.Remove(tokenAcquisitionhost);
7979
services.Remove(authenticationHeaderCreator);
8080
services.Remove(tokenAcquirerFactory);
81+
tokenAcquirerFactory = null;
8182
}
8283
else
8384
{
@@ -108,6 +109,12 @@ public static IServiceCollection AddTokenAcquisition(
108109
// .NET FW.
109110
services.AddSingleton<ITokenAcquisition, TokenAcquisition>();
110111
services.AddSingleton<ITokenAcquisitionHost, DefaultTokenAcquisitionHost>();
112+
113+
// To support ASP.NET Core 2.x on .NET FW. It won't use the TokenAcquirerFactory.GetDefaultInstance()
114+
if (tokenAcquirerFactory == null)
115+
{
116+
services.AddSingleton<ITokenAcquirerFactory, DefaultTokenAcquirerFactoryImplementation>();
117+
}
111118
#endif
112119
services.AddSingleton(s => (ITokenAcquisitionInternal)s.GetRequiredService<ITokenAcquisition>());
113120
services.AddSingleton<IAuthorizationHeaderProvider, DefaultAuthorizationHeaderProvider>();

tests/DevApps/aspnet-mvc/OwinWebApi/Web.config

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
</dependentAssembly>
5959
<dependentAssembly>
6060
<assemblyIdentity name="System.Memory" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
61-
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1"/>
61+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2"/>
6262
</dependentAssembly>
6363
<dependentAssembly>
6464
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
65-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
65+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
6666
</dependentAssembly>
6767
<dependentAssembly>
6868
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
@@ -78,27 +78,27 @@
7878
</dependentAssembly>
7979
<dependentAssembly>
8080
<assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
81-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
81+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
8282
</dependentAssembly>
8383
<dependentAssembly>
8484
<assemblyIdentity name="Microsoft.IdentityModel.Protocols.WsFederation" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
8585
<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0"/>
8686
</dependentAssembly>
8787
<dependentAssembly>
8888
<assemblyIdentity name="Microsoft.IdentityModel.Protocols.OpenIdConnect" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
89-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
89+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
9090
</dependentAssembly>
9191
<dependentAssembly>
9292
<assemblyIdentity name="Microsoft.IdentityModel.Protocols" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
93-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
93+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
9494
</dependentAssembly>
9595
<dependentAssembly>
9696
<assemblyIdentity name="Microsoft.IdentityModel.Logging" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
97-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
97+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
9898
</dependentAssembly>
9999
<dependentAssembly>
100100
<assemblyIdentity name="Microsoft.IdentityModel.Abstractions" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
101-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
101+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
102102
</dependentAssembly>
103103
<dependentAssembly>
104104
<assemblyIdentity name="Microsoft.Identity.Client" publicKeyToken="0A613F4DD989E8AE" culture="neutral"/>

tests/DevApps/aspnet-mvc/OwinWebApp/Web.config

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
</dependentAssembly>
6060
<dependentAssembly>
6161
<assemblyIdentity name="System.Memory" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
62-
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1"/>
62+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2"/>
6363
</dependentAssembly>
6464
<dependentAssembly>
6565
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
66-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
66+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
6767
</dependentAssembly>
6868
<dependentAssembly>
6969
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
@@ -79,27 +79,27 @@
7979
</dependentAssembly>
8080
<dependentAssembly>
8181
<assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
82-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
82+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
8383
</dependentAssembly>
8484
<dependentAssembly>
8585
<assemblyIdentity name="Microsoft.IdentityModel.Protocols.WsFederation" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
8686
<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0"/>
8787
</dependentAssembly>
8888
<dependentAssembly>
8989
<assemblyIdentity name="Microsoft.IdentityModel.Protocols.OpenIdConnect" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
90-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
90+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
9191
</dependentAssembly>
9292
<dependentAssembly>
9393
<assemblyIdentity name="Microsoft.IdentityModel.Protocols" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
94-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
94+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
9595
</dependentAssembly>
9696
<dependentAssembly>
9797
<assemblyIdentity name="Microsoft.IdentityModel.Logging" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
98-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
98+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
9999
</dependentAssembly>
100100
<dependentAssembly>
101101
<assemblyIdentity name="Microsoft.IdentityModel.Abstractions" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
102-
<bindingRedirect oldVersion="0.0.0.0-6.35.0.0" newVersion="6.35.0.0"/>
102+
<bindingRedirect oldVersion="0.0.0.0-7.5.2.0" newVersion="7.5.2.0"/>
103103
</dependentAssembly>
104104
<dependentAssembly>
105105
<assemblyIdentity name="Microsoft.Identity.Client" publicKeyToken="0A613F4DD989E8AE" culture="neutral"/>

0 commit comments

Comments
 (0)