You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace AuthStudy.Authentication.Browser
|
|
{
|
|
public static class BrowserAuthenticationExtensions
|
|
{
|
|
#region 基于接口的扩展注册
|
|
public static IServiceCollection AddBrowserAuthentication
|
|
(
|
|
this IServiceCollection builder,
|
|
string AuthenticationSchemeName,
|
|
string AuthenticationDispalyName,
|
|
BrowserAuthenticationOptions Option
|
|
)
|
|
{
|
|
if (builder == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(builder));
|
|
}
|
|
|
|
builder.AddService(Option);
|
|
|
|
builder.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = AuthenticationSchemeName;
|
|
options.DefaultAuthenticateScheme = AuthenticationSchemeName;
|
|
options.DefaultChallengeScheme = AuthenticationSchemeName;
|
|
options.DefaultForbidScheme = AuthenticationSchemeName;
|
|
options.DefaultSignInScheme = AuthenticationSchemeName;
|
|
options.DefaultSignOutScheme = AuthenticationSchemeName;
|
|
|
|
options.AddScheme<BrowserAuthenticationBaseHandler>(AuthenticationSchemeName, AuthenticationDispalyName);
|
|
});
|
|
|
|
return builder;
|
|
}
|
|
|
|
|
|
private static IServiceCollection AddService(this IServiceCollection builder, BrowserAuthenticationOptions option)
|
|
{
|
|
BrowserAuthenticationOptions defaultOption = option ?? new();
|
|
builder.AddSingleton(defaultOption);
|
|
builder.AddSingleton<BrowserAuthenticationBaseHandler>();
|
|
|
|
return builder;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 基于默认基数的扩展注册
|
|
#endregion
|
|
}
|
|
}
|