zoukankan      html  css  js  c++  java
  • 4.0AuthenticationServiceCollectionExtensions&AuthenticationCoreServiceCollectionExtensions

    using System;
    using Microsoft.AspNetCore.Authentication;
    using Microsoft.Extensions.DependencyInjection.Extensions;
    using Microsoft.Extensions.Options;
    
    namespace Microsoft.Extensions.DependencyInjection
    {
        /// <summary>
        /// Extension methods for setting up authentication services in an <see cref="IServiceCollection" />.
        /// </summary>
        public static class AuthenticationServiceCollectionExtensions
        {
            /// <summary>
            /// Registers services required by authentication services.
            /// </summary>
            /// <param name="services">The <see cref="IServiceCollection"/>.</param>
            /// <returns>A <see cref="AuthenticationBuilder"/> that can be used to further configure authentication.</returns>
            public static AuthenticationBuilder AddAuthentication(this IServiceCollection services)
            {
                if (services == null)
                {
                    throw new ArgumentNullException(nameof(services));
                }
    
                services.AddAuthenticationCore();
                services.AddDataProtection();
                services.AddWebEncoders();
                services.TryAddSingleton<ISystemClock, SystemClock>();
                return new AuthenticationBuilder(services);
            }
    
            /// <summary>
            /// Registers services required by authentication services. <paramref name="defaultScheme"/> specifies the name of the
            /// scheme to use by default when a specific scheme isn't requested.
            /// </summary>
            /// <param name="services">The <see cref="IServiceCollection"/>.</param>
            /// <param name="defaultScheme">The default scheme used as a fallback for all other schemes.</param>
            /// <returns>A <see cref="AuthenticationBuilder"/> that can be used to further configure authentication.</returns>
            public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, string defaultScheme)
                => services.AddAuthentication(o => o.DefaultScheme = defaultScheme);
    
            /// <summary>
            /// Registers services required by authentication services and configures <see cref="AuthenticationOptions"/>.
            /// </summary>
            /// <param name="services">The <see cref="IServiceCollection"/>.</param>
            /// <param name="configureOptions">A delegate to configure <see cref="AuthenticationOptions"/>.</param>
            /// <returns>A <see cref="AuthenticationBuilder"/> that can be used to further configure authentication.</returns>
            public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, Action<AuthenticationOptions> configureOptions)
            {
                if (services == null)
                {
                    throw new ArgumentNullException(nameof(services));
                }
    
                if (configureOptions == null)
                {
                    throw new ArgumentNullException(nameof(configureOptions));
                }
    
                var builder = services.AddAuthentication();
                services.Configure(configureOptions);
                return builder;
            }
    
        }
    }
    using System;
    using Microsoft.AspNetCore.Authentication;
    using Microsoft.Extensions.DependencyInjection.Extensions;
    
    namespace Microsoft.Extensions.DependencyInjection
    {
        /// <summary>
        /// Extension methods for setting up authentication services in an <see cref="IServiceCollection" />.
        /// </summary>
        public static class AuthenticationCoreServiceCollectionExtensions
        {
            /// <summary>
            /// Add core authentication services needed for <see cref="IAuthenticationService"/>.
            /// </summary>
            /// <param name="services">The <see cref="IServiceCollection"/>.</param>
            /// <returns>The service collection.</returns>
            public static IServiceCollection AddAuthenticationCore(this IServiceCollection services)
            {
                if (services == null)
                {
                    throw new ArgumentNullException(nameof(services));
                }
    
                services.TryAddScoped<IAuthenticationService, AuthenticationService>();
                services.TryAddSingleton<IClaimsTransformation, NoopClaimsTransformation>(); // Can be replaced with scoped ones that use DbContext
                services.TryAddScoped<IAuthenticationHandlerProvider, AuthenticationHandlerProvider>();
                services.TryAddSingleton<IAuthenticationSchemeProvider, AuthenticationSchemeProvider>();
                return services;
            }
    
            /// <summary>
            /// Add core authentication services needed for <see cref="IAuthenticationService"/>.
            /// </summary>
            /// <param name="services">The <see cref="IServiceCollection"/>.</param>
            /// <param name="configureOptions">Used to configure the <see cref="AuthenticationOptions"/>.</param>
            /// <returns>The service collection.</returns>
            public static IServiceCollection AddAuthenticationCore(this IServiceCollection services, Action<AuthenticationOptions> configureOptions) {
                if (services == null)
                {
                    throw new ArgumentNullException(nameof(services));
                }
    
                if (configureOptions == null)
                {
                    throw new ArgumentNullException(nameof(configureOptions));
                }
    
                services.AddAuthenticationCore();
                services.Configure(configureOptions);
                return services;
            }
        }
    }
  • 相关阅读:
    Python接口自动化(十一) Json数据处理
    Python接口自动化(十)重定向(Location)
    数据结构——定长串的实现
    数据结构图的建立和遍历(邻接表、邻接矩阵)
    数据结构——栈的顺序存储表示
    数据结构单链队列——链式存储实现
    数据结构线性表——链表实现
    数据结构顺序表——线性表实现
    HDU-1874-畅通工程续 (最短路 贝尔曼Bellman_Ford)
    Hrbust-2122 旅行(最短路)
  • 原文地址:https://www.cnblogs.com/htlp/p/15256936.html
Copyright © 2011-2022 走看看