Merge branch 'develop' into 'release'
Develop See merge request yescent/yes.blog!5
This commit is contained in:
@@ -30,9 +30,9 @@ namespace Yes.Blog
|
||||
|
||||
services.AddAuthorization();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
services.AddEndpointsApiExplorer();
|
||||
|
||||
builder.Services.AddOpenApi(options =>
|
||||
services.AddOpenApi(options =>
|
||||
{
|
||||
options.AddDocumentTransformer((document, context, cancellationToken) =>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Yes.Blog.Endpoints.Admins;
|
||||
|
||||
|
||||
namespace Yes.Blog.Endpoints.Blogs
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Yes.Infrastructure.Authorizations
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace Yes.Infrastructure.Authorizations
|
||||
{
|
||||
public static class AuthenticationExtensions
|
||||
{
|
||||
@@ -16,10 +18,21 @@
|
||||
options.Events.OnRedirectToAccessDenied =
|
||||
options.Events.OnRedirectToLogin = c =>
|
||||
{
|
||||
c.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
return Task.FromResult(Result.Error("请登录后操作!"));
|
||||
if(c.Request.GetDisplayUrl().Contains("/api"))
|
||||
{
|
||||
c.Response.ContentType = "application/json";
|
||||
c.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
return Task.FromResult(Result.Error("请登录后操作!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
c.Response.Redirect(c.RedirectUri);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
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