Skip to content

Commit

Permalink
do not call build service provider (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyf19 authored Jun 28, 2020
1 parent f3fa25b commit f2bc3a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Microsoft.Identity.Web/Microsoft.Identity.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>$(DefineConstants);DOTNET_CORE_31</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
<DefineConstants>$(DefineConstants);DOTNET_50</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<!-- The MSAL.snk has both private and public keys -->
<DelaySign>false</DelaySign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ public static AuthenticationBuilder AddMicrosoftWebApi(
builder.Services.AddSingleton<IJwtBearerMiddlewareDiagnostics, JwtBearerMiddlewareDiagnostics>();
builder.Services.AddHttpClient();

#if DOTNET_CORE_31
// Change the authentication configuration to accommodate the Microsoft identity platform endpoint (v2.0).
builder.AddJwtBearer(jwtBearerScheme, options =>
{
// TODO: replace by the work around that @Tratcher will provider
IServiceProvider serviceProvider = builder.Services.BuildServiceProvider();
#else
builder.AddJwtBearer<IServiceProvider>(jwtBearerScheme, (options, serviceProvider) =>
{
#endif
// TODO:
// Suspect. Why not get the IOption<MicrosoftIdentityOptions>?
MicrosoftIdentityOptions microsoftIdentityOptions = new MicrosoftIdentityOptions(); // configuration.GetSection(configSectionName).Get<MicrosoftIdentityOptions>();
Expand Down Expand Up @@ -142,7 +149,7 @@ public static AuthenticationBuilder AddMicrosoftWebApi(

if (subscribeToJwtBearerMiddlewareDiagnosticsEvents)
{
var diags = builder.Services.BuildServiceProvider().GetRequiredService<IJwtBearerMiddlewareDiagnostics>();
var diags = serviceProvider.GetRequiredService<IJwtBearerMiddlewareDiagnostics>();

diags.Subscribe(options.Events);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ public static AuthenticationBuilder AddMicrosoftWebApp(

builder.Services.AddSingleton<IOpenIdConnectMiddlewareDiagnostics, OpenIdConnectMiddlewareDiagnostics>();
builder.AddCookie(cookieScheme);

#if DOTNET_CORE_31
builder.AddOpenIdConnect(openIdConnectScheme, options =>
{
// TODO: replace by the work around that @Tratcher will provider
IServiceProvider serviceProvider = builder.Services.BuildServiceProvider();
#else
builder.AddOpenIdConnect<IServiceProvider>(openIdConnectScheme, (options, serviceProvider) =>
{
#endif
options.SignInScheme = cookieScheme;

if (string.IsNullOrWhiteSpace(options.Authority))
Expand Down Expand Up @@ -180,7 +188,7 @@ public static AuthenticationBuilder AddMicrosoftWebApp(

if (subscribeToOpenIdConnectMiddlewareDiagnosticsEvents)
{
var diags = builder.Services.BuildServiceProvider().GetRequiredService<IOpenIdConnectMiddlewareDiagnostics>();
var diags = serviceProvider.GetRequiredService<IOpenIdConnectMiddlewareDiagnostics>();

diags.Subscribe(options.Events);
}
Expand Down

0 comments on commit f2bc3a7

Please sign in to comment.