// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Authentication.Cookies { /// /// Used to setup defaults for all . /// public class PostConfigureCookieAuthenticationOptions : IPostConfigureOptions { private readonly IDataProtectionProvider _dp; public PostConfigureCookieAuthenticationOptions(IDataProtectionProvider dataProtection) { _dp = dataProtection; } /// /// Invoked to post configure a TOptions instance. /// /// The name of the options instance being configured. /// The options instance to configure. public void PostConfigure(string name, CookieAuthenticationOptions options) { options.DataProtectionProvider = options.DataProtectionProvider ?? _dp; if (string.IsNullOrEmpty(options.Cookie.Name)) { options.Cookie.Name = CookieAuthenticationDefaults.CookiePrefix + name; } if (options.TicketDataFormat == null) { // Note: the purpose for the data protector must remain fixed for interop to work. var dataProtector = options.DataProtectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", name, "v2"); options.TicketDataFormat = new TicketDataFormat(dataProtector); } if (options.CookieManager == null) { options.CookieManager = new ChunkingCookieManager(); } if (!options.LoginPath.HasValue) { options.LoginPath = CookieAuthenticationDefaults.LoginPath; } if (!options.LogoutPath.HasValue) { options.LogoutPath = CookieAuthenticationDefaults.LogoutPath; } if (!options.AccessDeniedPath.HasValue) { options.AccessDeniedPath = CookieAuthenticationDefaults.AccessDeniedPath; } } } }