1
This commit is contained in:
@@ -5,6 +5,16 @@
|
||||
public static IServiceCollection AddUserAuthentication(this IServiceCollection services)
|
||||
{
|
||||
services.AddAuthentication(AuthenticationScheme.UserScheme)
|
||||
.AddCookie(AuthenticationScheme.UserScheme, options =>
|
||||
{
|
||||
options.Cookie.Name = AuthenticationScheme.UserScheme;
|
||||
options.LoginPath = "/admin/login";
|
||||
options.LogoutPath = "/admin/logout";
|
||||
options.ExpireTimeSpan = TimeSpan.FromDays(3);
|
||||
options.SlidingExpiration = true;
|
||||
});
|
||||
|
||||
services.AddAuthentication(AuthenticationScheme.UserApiScheme)
|
||||
.AddCookie(AuthenticationScheme.UserScheme, options =>
|
||||
{
|
||||
options.Cookie.Name = AuthenticationScheme.UserScheme;
|
||||
@@ -16,8 +26,8 @@
|
||||
options.Events.OnRedirectToAccessDenied =
|
||||
options.Events.OnRedirectToLogin = c =>
|
||||
{
|
||||
c.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
return Task.FromResult(Result.Error("请登录后操作!"));
|
||||
c.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
return Task.FromResult(Result.Error("请登录后操作!"));
|
||||
};
|
||||
});
|
||||
return services;
|
||||
|
||||
@@ -5,5 +5,7 @@
|
||||
public const string MerchanScheme = "merchan";
|
||||
|
||||
public const string UserScheme = "user";
|
||||
|
||||
public const string UserApiScheme = "userapi";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Yes.Infrastructure.Authorizations.User
|
||||
{
|
||||
|
||||
|
||||
public class UserApiAuthorizeAttribute : AuthorizeAttribute
|
||||
{
|
||||
public UserApiAuthorizeAttribute()
|
||||
{
|
||||
AuthenticationSchemes = AuthenticationScheme.UserApiScheme;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user