// 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 System.Collections.Generic; using Microsoft.AspNetCore.Http; namespace Microsoft.AspNetCore.Authentication { public class AuthenticationOptions { private readonly IList _schemes = new List(); /// /// Returns the schemes in the order they were added (important for request handling priority) /// public IEnumerable Schemes => _schemes; /// /// Maps schemes by name. /// public IDictionary SchemeMap { get; } = new Dictionary(StringComparer.Ordinal); /// /// Adds an . /// /// The name of the scheme being added. /// Configures the scheme. public void AddScheme(string name, Action configureBuilder) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (configureBuilder == null) { throw new ArgumentNullException(nameof(configureBuilder)); } if (SchemeMap.ContainsKey(name)) { throw new InvalidOperationException("Scheme already exists: " + name); } var builder = new AuthenticationSchemeBuilder(name); configureBuilder(builder); _schemes.Add(builder); SchemeMap[name] = builder; } /// /// Adds an . /// /// The responsible for the scheme. /// The name of the scheme being added. /// The display name for the scheme. public void AddScheme(string name, string displayName) where THandler : IAuthenticationHandler => AddScheme(name, b => { b.DisplayName = displayName; b.HandlerType = typeof(THandler); }); /// /// Used by as the fallback default scheme for all the other defaults."/>. /// public string DefaultScheme { get; set; } /// /// Used by as the default scheme by . /// public string DefaultAuthenticateScheme { get; set; } /// /// Used by as the default scheme by . /// public string DefaultSignInScheme { get; set; } /// /// Used by as the default scheme by . /// public string DefaultSignOutScheme { get; set; } /// /// Used by as the default scheme by . /// public string DefaultChallengeScheme { get; set; } /// /// Used by as the default scheme by . /// public string DefaultForbidScheme { get; set; } } }