AddAuthentication

// C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\7.0.5\Microsoft.AspNetCore.Authentication.dll
// Microsoft.AspNetCore.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

https://www.nuget.org/packages/Microsoft.AspNetCore.App.Ref/7.0.5

This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/d47e49e9c1e173ac90821f7e89cc38e710274241

aspnetcore/src/Security/Authentication/Core/src/AuthenticationServiceCollectionExtensions.cs at d47e49e9c1e173ac90821f7e89cc38e710274241 · dotnet/aspnetcore (github.com)


    /// <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>();
        services.TryAddSingleton<IAuthenticationConfigurationProvider, DefaultAuthenticationConfigurationProvider>();

        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;
    }

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(61)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-07-21 System.Web.Http.dll 所在的NuGet
2019-07-21 一个可乐瓶自制捕蟑螂神器
2019-07-21 compare across commits online
2015-07-21 When to use DataContract and DataMember attributes?
2015-07-21 Learning WCF Chapter2 Data Contracts
2014-07-21 C#中线程的使用[Thread in C#]
点击右上角即可分享
微信分享提示