ow
This commit is contained in:
commit
f05d2d215f
678 files changed
+73865
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace CloudBuilder.Core.Authorization
|
||||
{
|
||||
public class AuthorizationHandler : IAuthorizationHandler, IAuthorize
|
||||
{
|
||||
/// <summary>
|
||||
/// 身份认证Authorize
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Task HandleAsync(AuthorizationHandlerContext context)
|
||||
{
|
||||
if (context.HasFailed)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// 判断身份认证是否通过
|
||||
var isAuthenticated = context.User.Identity.IsAuthenticated;
|
||||
if (isAuthenticated)
|
||||
{
|
||||
context.Succeed(context.PendingRequirements.FirstOrDefault()!);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
context.Fail();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user