首页 > 编程语言 >asp.netcore Authentication

asp.netcore Authentication

时间:2022-12-21 14:35:25浏览次数:71  
标签:use asp authenticationScheme netcore builder Authentication cookie AddCookie

Authentication is for getting the user infomation from cookie/token..

We use Authentication like this:

builder.Services.AddAuthentication("cookie")
.AddCookie();

the  AddCookie() define we get info from cookie;

    public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action<CookieAuthenticationOptions> configureOptions)
    {
        builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<CookieAuthenticationOptions>, PostConfigureCookieAuthenticationOptions>());
        builder.Services.AddOptions<CookieAuthenticationOptions>(authenticationScheme).Validate(o => o.Cookie.Expiration == null, "Cookie.Expiration is ignored, use ExpireTimeSpan instead.");
        return builder.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler>(authenticationScheme, displayName, configureOptions);
    }

The first line define where the Options<CookieAuthenticationOptions> come from when we use it in progarm.

The implenment define loginpath properties,etc

The CookieManager deine how to get the cookie string.

 

标签:use,asp,authenticationScheme,netcore,builder,Authentication,cookie,AddCookie
From: https://www.cnblogs.com/qgbo/p/16996191.html

相关文章