This commit is contained in:
2025-05-07 00:10:03 +08:00
parent 905a240121
commit dd86a5a818
5 changed files with 29 additions and 5 deletions

View File

@@ -30,9 +30,9 @@ namespace Yes.Blog
services.AddAuthorization(); services.AddAuthorization();
builder.Services.AddEndpointsApiExplorer(); services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi(options => services.AddOpenApi(options =>
{ {
options.AddDocumentTransformer((document, context, cancellationToken) => options.AddDocumentTransformer((document, context, cancellationToken) =>
{ {

View File

@@ -1,4 +1,4 @@
using Yes.Blog.Endpoints.Admins; 
namespace Yes.Blog.Endpoints.Blogs namespace Yes.Blog.Endpoints.Blogs
{ {

View File

@@ -5,6 +5,16 @@
public static IServiceCollection AddUserAuthentication(this IServiceCollection services) public static IServiceCollection AddUserAuthentication(this IServiceCollection services)
{ {
services.AddAuthentication(AuthenticationScheme.UserScheme) 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 => .AddCookie(AuthenticationScheme.UserScheme, options =>
{ {
options.Cookie.Name = AuthenticationScheme.UserScheme; options.Cookie.Name = AuthenticationScheme.UserScheme;

View File

@@ -5,5 +5,7 @@
public const string MerchanScheme = "merchan"; public const string MerchanScheme = "merchan";
public const string UserScheme = "user"; public const string UserScheme = "user";
public const string UserApiScheme = "userapi";
} }
} }

View File

@@ -0,0 +1,12 @@
namespace Yes.Infrastructure.Authorizations.User
{
public class UserApiAuthorizeAttribute : AuthorizeAttribute
{
public UserApiAuthorizeAttribute()
{
AuthenticationSchemes = AuthenticationScheme.UserApiScheme;
}
}
}