Пример #1
0
 public AuthorizationFilter(IAuthorizationService authorizationService,
                            IActionExceptionHandler actionResultFactory,
                            IOptions <AspNetAuthorizationOptions> options)
 {
     this.authorizationService = authorizationService;
     this.actionResultFactory  = actionResultFactory;
     this.options = options;
 }
        public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, AuthorizationFilterContext context, AspNetAuthorizationOptions options, CancellationToken cancellationToken)
        {
            if (!(context.ActionDescriptor is ControllerActionDescriptor actionDescriptor))
            {
                return;
            }

            var authorizeInfo = GetAuthorizeInfo(actionDescriptor, options);

            if (authorizeInfo != null)
            {
                await authorizationService.AuthorizeAsync(new IAuthorizeInfo[] { authorizeInfo }, cancellationToken);
            }
        }