Reputation: 278
I have looked at a bunch of similar issues on StackOverflow similar to this but none of the solutions have worked for me.
This issue is driving me nuts!
The main difference I have from many of the similar ones here is that I have only ONE server behind the load balancer, so the issue is not that my requests are going to different servers. I have implemented Data Protection middleware, changed my callback path, tried to capture error events, added a cache for state data, etc. Nothing has solved this. I don't know what I am missing.
If anyone can provide me some insight on this, I would greatly appreciate it.
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.ClientId = Configuration["IdServerClientId"];
options.ClientSecret = Configuration["IdServerClientSecret"];
options.Authority = Configuration["IdServerBaseUri"];
options.CallbackPath = "/sign-in-oidc2";
options.RequireHttpsMetadata = false;
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.TokenValidationParameters = new TokenValidationParameters()
{
NameClaimType = "name"
};
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.Events = new OpenIdConnectEvents()
{
//OnRedirectToIdentityProvider = OnRedirectToProvider,
OnRemoteFailure = OnRemoteFailure,
OnAuthenticationFailed = OnAuthenticationFailed
};
});
services.AddOidcStateDataFormatterCache("foo");
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPersistenceLocation"]));
Upvotes: 2
Views: 7693
Reputation: 278
Found the answer here if anyone else encounters this:
In the Configure method on Startup, need to add this for handling http/https conflicts.
app.Use((context, next) =>
{
context.Request.Scheme = "https";
return next();
});
Upvotes: 4