Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jan 21, 2024
1 parent c3e8ce9 commit 39ba4ef
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions TechStacks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@
options.ClientSecret = Environment.GetEnvironmentVariable("GH_CLIENT_SECRET") ?? config["oauth.github.ClientSecret"]!;
options.Scope.Add("user:email");
options.CallbackPath = "/signin-oidc-github";
// Force OAuth redirect as https
options.Events.OnRedirectToAuthorizationEndpoint = ctx =>
{
var uriBuilder = new UriBuilder(ctx.RedirectUri) {
Scheme = "https",
Port = -1 // default port for scheme
};
var newUri = uriBuilder.ToString();
LogManager.GetLogger(typeof(Program)).DebugFormat("Changing URL from '{0}' to '{1}'",
ctx.RedirectUri, newUri);
ctx.RedirectUri = newUri;
return Task.FromResult(0);
};
})
.AddScheme<AuthenticationSchemeOptions,BasicAuthenticationHandler<ApplicationUser,int>>(BasicAuthenticationHandler.Scheme, null)
.AddIdentityCookies(options => options.DisableRedirectsForApis());
Expand Down Expand Up @@ -82,10 +69,7 @@

services.Configure<ForwardedHeadersOptions>(options => {
//https://github.com/aspnet/IISIntegration/issues/140#issuecomment-215135928
//https://github.com/IdentityServer/IdentityServer4/issues/324#issuecomment-309021465
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.KnownProxies.Clear();
options.KnownProxies.Clear();
});

services.AddRazorPages();
Expand Down Expand Up @@ -132,6 +116,11 @@
});

var app = builder.Build();
// Force Request HTTPS to OAuth redirects include https://
app.Use((ctx, next) => {
ctx.Request.Scheme = "https";
return next();
});

app.UseMigrationsEndPoint();
app.UseSwagger();
Expand Down

0 comments on commit 39ba4ef

Please sign in to comment.