Created
April 23, 2020 22:52
-
-
Save nwrox/98e66c4bc988f26ef4bc2510901166f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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