Skip to content

Commit

Permalink
Debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceredron committed Oct 14, 2024
1 parent 8a3f31a commit a5782ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
public class CascadeAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
private readonly IAuthenticationSchemeProvider _schemeProvider;
private readonly IHttpContextAccessor _httpContextAccessor;

public CascadeAuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock,
IAuthenticationSchemeProvider schemeProvider)
IAuthenticationSchemeProvider schemeProvider,
IHttpContextAccessor httpContextAccessor)
: base(options, logger, encoder, clock)
{
_schemeProvider = schemeProvider;
_httpContextAccessor = httpContextAccessor;
}

protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
Expand Down Expand Up @@ -51,6 +54,10 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
else
{
Logger.LogInformation($"Authentication failed with scheme: {schemeName}. Reason: {result.Failure?.Message}: {result.Failure?.StackTrace}");
foreach (var item in _httpContextAccessor.HttpContext?.Items)
{
Logger.LogInformation(schemeName + " " + item.Key + " " + item.Value);
}
}

// If it's OpenIdConnect and it failed, we don't want to redirect yet
Expand Down
10 changes: 6 additions & 4 deletions src/Altinn.Correspondence.API/Auth/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ public static void ConfigureAuthentication(this IServiceCollection services, ICo
{
options.Cookie.Name = "CorrespondenceIdportenSession";
options.Cookie.SameSite = SameSiteMode.None;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.Cookie.IsEssential = true;
options.ExpireTimeSpan = TimeSpan.FromSeconds(10); // Must be transient/short-lived
options.ExpireTimeSpan = TimeSpan.FromSeconds(60); // Must be transient/short-lived
options.SlidingExpiration = false;
})
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
options.NonceCookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.NonceCookie.SameSite = SameSiteMode.None;
options.CorrelationCookie.SameSite = SameSiteMode.None;
options.AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet;
options.ResponseMode = OpenIdConnectResponseMode.FormPost;
options.Authority = idPortenSettings.Issuer;
Expand Down

0 comments on commit a5782ae

Please sign in to comment.