Skip to content

Instantly share code, notes, and snippets.

@nwrox
Created April 23, 2020 22:52
Show Gist options
  • Save nwrox/98e66c4bc988f26ef4bc2510901166f9 to your computer and use it in GitHub Desktop.
Save nwrox/98e66c4bc988f26ef4bc2510901166f9 to your computer and use it in GitHub Desktop.
var appOptions = _conf.GetSection("AppOptions");
var purposes = appOptions.GetSection("CookieAadPurposes")
.GetChildren();
services.AddCors(options =>
{
options.AddPolicy(CorsPolicyName,
//.AllowCredentials()
builder => builder.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
.Build()
);
});
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication();
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@$"{appOptions["CookieKeyPath"]}"))
.SetApplicationName($"{purposes.FirstOrDefault()}")
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings
.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
options.SerializerSettings
.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
});
services.AddInfrastructure();
services.AddSingleton<ICookieDataProtector, CookieDataProtector>();
services.AddSingleton<IHelper, Helper>();
services.Configure<AppOptions>(options =>
{
appOptions.Bind(options);
});
services.Configure<ForwardedHeadersOptions>(options => {
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.KnownNetworks
.Clear();
options.KnownProxies
.Clear();
options.RequireHeaderSymmetry = false;
});
services.ConfigureOptions<CustomIdentityServerOptions>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment