Skip to content

Commit d8ea4b0

Browse files
feat: Update MX.Observability.ApplicationInsights package version to 1.0.7 and refactor authentication configuration
1 parent 52198cc commit d8ea4b0

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/XtremeIdiots.Portal.Web/Areas/Identity/IdentityHostingStartup.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,20 @@ private static void ConfigureCookiePolicy(IServiceCollection services)
8585

8686
private static void ConfigureAuthentication(IServiceCollection services, IConfiguration configuration)
8787
{
88-
services.AddAuthentication(options =>
89-
{
90-
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
91-
options.DefaultChallengeScheme = OAuthSchemeName;
92-
})
93-
.AddCookie(options =>
94-
{
95-
options.AccessDeniedPath = "/Errors/Display/401";
96-
options.Cookie.Name = CookieName;
97-
options.Cookie.HttpOnly = true;
98-
options.Cookie.IsEssential = true;
99-
options.ExpireTimeSpan = TimeSpan.FromDays(CookieExpirationDays);
100-
options.LoginPath = "/Identity/Login";
101-
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
102-
options.SlidingExpiration = true;
103-
})
88+
// Do not override Identity's default schemes — AddIdentity already sets:
89+
// DefaultAuthenticateScheme = Identity.Application
90+
// DefaultSignInScheme = Identity.External
91+
// DefaultChallengeScheme = Identity.Application (login page redirect)
92+
// The controller explicitly challenges "XtremeIdiots" when needed.
93+
services.AddAuthentication()
10494
.AddOAuth(OAuthSchemeName, options =>
10595
{
96+
// Sign into the external cookie so SignInManager.GetExternalLoginInfoAsync() works
97+
options.SignInScheme = IdentityConstants.ExternalScheme;
98+
99+
// Must be essential so cookie consent policy doesn't block the correlation cookie
100+
options.CorrelationCookie.IsEssential = true;
101+
106102
options.ClientId = GetConfigurationValue(configuration, AuthClientIdKey) ?? throw new InvalidOperationException("OAuth client ID is required");
107103
options.ClientSecret = GetConfigurationValue(configuration, AuthClientSecretKey) ?? throw new InvalidOperationException("OAuth client secret is required");
108104

@@ -148,6 +144,22 @@ private static void ConfigureAuthentication(IServiceCollection services, IConfig
148144
}
149145
};
150146
});
147+
148+
// Configure Identity's application cookie (replaces the removed AddCookie call)
149+
services.ConfigureApplicationCookie(options =>
150+
{
151+
options.AccessDeniedPath = "/Errors/Display/401";
152+
options.Cookie.Name = CookieName;
153+
options.Cookie.HttpOnly = true;
154+
options.Cookie.IsEssential = true;
155+
options.ExpireTimeSpan = TimeSpan.FromDays(CookieExpirationDays);
156+
options.LoginPath = "/Identity/Login";
157+
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
158+
options.SlidingExpiration = true;
159+
});
160+
161+
// Ensure the external cookie used during OAuth callback is not blocked by consent policy
162+
services.ConfigureExternalCookie(options => options.Cookie.IsEssential = true);
151163
}
152164

153165
private static void ConfigureDataProtection(IServiceCollection services)

src/XtremeIdiots.Portal.Web/XtremeIdiots.Portal.Web.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</PackageReference>
4545
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.3" />
4646
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.12" />
47-
<PackageReference Include="MX.Observability.ApplicationInsights" Version="1.0.5" />
47+
<PackageReference Include="MX.Observability.ApplicationInsights" Version="1.0.7" />
4848
<PackageReference Include="MX.Api.Abstractions" Version="2.3.31" />
4949
<PackageReference Include="MX.Api.Client" Version="2.3.31" />
5050
<PackageReference Include="XtremeIdiots.Portal.Integrations.Servers.Api.Client.V1" Version="2.1.138" />
@@ -87,3 +87,5 @@
8787

8888

8989

90+
91+

0 commit comments

Comments
 (0)