OpenIdConnect leitet zu http statt zu https weiterC#

Ein Treffpunkt für C#-Programmierer
Guest
 OpenIdConnect leitet zu http statt zu https weiter

Post by Guest »

Ich habe ein Problem mit der Integration einer ASP.NET CORE 5.0-Webanwendung in OKTA.
Mein Unternehmen benötigt die Integration aller Webanwendungen in OKTA. Diese App, über die ich geschrieben habe, wird auf dem Fargate-Cluster als Linux-Container gehostet (und verwendet Application Load Balancer + AWS-Zertifikat zur Verwendung von HTTPS). Der Container läuft auf HTTP und wird von ALB auf HTTPS umgeleitet.
Wenn ich auf den Hostnamen der Anwendung (https://exampleapp.companyname.com) zugreife, versucht er, mich zum folgenden Link umzuleiten:

Code: Select all

https://dev-1234567.okta.com/oauth2/default/v1/authorize?client_id=xyz&redirect_uri=http://exampleapp.companyname.com/signin-oidc&response_type=code&scope=openid profile email&code_challenge=xyz&code_challenge_method=S256&response_mode=form_post&nonce=xyz&x-client-ver=6.7.1.0
Wie Sie sehen können, verweist mich dieser Redirect_uri auf den HTTP-Endpunkt, was zu Fehler 400 führt (weil ich in Okta keinen HTTP-Anmelde-Umleitungs-URI angegeben habe, sondern nur HTTPS).
Warum versucht Okta, mich zu http:// umzuleiten, wenn ich über https:// auf die Seite zugreife?
Wenn ich versuche, die http://-Adresse zu Okta-Anmelde-URIs hinzuzufügen, Wenn ich versuche, auf die Seite zuzugreifen, tritt dieser Fehler auf tritt auf:

Code: Select all

The information you’re about to submit is not secure
und wenn ich auf die Schaltfläche „Trotzdem senden“ klicke, wird auf der Seite der ASP.NET CORE-Fehler angezeigt:

Code: Select all

System.Exception: An error was encountered while handling the remote login.
---> System.Exception: OpenIdConnectAuthenticationHandler: message.State is null or empty.
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Wie kann ich dafür sorgen, dass es in dieser Umgebung funktioniert? Bei localhost funktioniert alles wie ein Zauber, HTTP und HTTPS. Vorher musste ich ein paar Tricks mit Cookies machen (SameSiteModes usw.), weil mir auf der Seite ein Korrelationsfehler angezeigt wurde.
Dies sind meine „ConfigureServices“ in Startup.cs, die im Projekt verwendet werden:

Code: Select all

public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();

services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.Cookie.SameSite = SameSiteMode.Lax;
})
.AddOpenIdConnect(options =>
{
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = oktaOrgUri;
options.RequireHttpsMetadata = true;
options.ClientId = oktaClientId;
options.ClientSecret = oktaClientSecret;
options.ResponseType = OpenIdConnectResponseType.Code;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.SaveTokens = true;
options.TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(oktaClientSecret)),
NameClaimType = "name",
RoleClaimType = "groups",
ValidateIssuer = true
};
});

services.AddAuthorization();
}

Code: Select all

oktaOrgUri = https://dev-1234567.okta.com/oauth2/default
oktaClientId and oktaClientSecret filled with values from Okta
Dann konfigurieren Sie es in Startup.cs

Code: Select all

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post