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.
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
2 years ago
|
using System;
|
||
2 years ago
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
2 years ago
|
using System.Runtime.CompilerServices;
|
||
2 years ago
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
using Microsoft.AspNetCore.Authentication;
|
||
2 years ago
|
using Microsoft.Extensions.DependencyInjection;
|
||
2 years ago
|
|
||
|
namespace AuthStudy.Authentication.Browser
|
||
|
{
|
||
2 years ago
|
public static class BaseBrowserAuthenticationExtensions
|
||
2 years ago
|
{
|
||
2 years ago
|
#region 基于接口的扩展注册
|
||
2 years ago
|
public static IServiceCollection AddBaseBrowserAuthentication
|
||
2 years ago
|
(
|
||
|
this IServiceCollection builder,
|
||
2 years ago
|
string authenticationSchemeName,
|
||
|
string authenticationDisplayName,
|
||
|
BrowserAuthenticationOptions authenticationOption
|
||
2 years ago
|
)
|
||
2 years ago
|
{
|
||
2 years ago
|
if (builder == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(builder));
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
builder.AddService(authenticationOption);
|
||
2 years ago
|
|
||
2 years ago
|
builder.AddAuthentication(options =>
|
||
|
{
|
||
2 years ago
|
options.DefaultScheme = authenticationSchemeName;
|
||
|
options.DefaultAuthenticateScheme = authenticationSchemeName;
|
||
|
options.DefaultChallengeScheme = authenticationSchemeName;
|
||
|
options.DefaultForbidScheme = authenticationSchemeName;
|
||
|
options.DefaultSignInScheme = authenticationSchemeName;
|
||
|
options.DefaultSignOutScheme = authenticationSchemeName;
|
||
|
|
||
|
options.AddScheme<BrowserAuthenticationBaseHandler>(authenticationSchemeName, authenticationDisplayName);
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
return builder;
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
|
||
2 years ago
|
private static IServiceCollection AddService(this IServiceCollection builder, BrowserAuthenticationOptions option)
|
||
2 years ago
|
{
|
||
2 years ago
|
BrowserAuthenticationOptions defaultOption = option ?? new(){AllowBrowsers = BrowserAuthenticationDefault.AllowBrowsers};
|
||
2 years ago
|
builder.AddSingleton(defaultOption);
|
||
2 years ago
|
builder.AddSingleton<BrowserAuthenticationBaseHandler>();
|
||
2 years ago
|
|
||
2 years ago
|
return builder;
|
||
|
}
|
||
2 years ago
|
|
||
|
#endregion
|
||
2 years ago
|
}
|
||
|
}
|