| | | 1 | | using System; |
| | | 2 | | using System.Linq; |
| | | 3 | | using System.Net; |
| | | 4 | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | 5 | | using SampleDotNetCore2RestStub.Exceptions; |
| | | 6 | | |
| | | 7 | | namespace SampleDotNetCore2RestStub.Attributes |
| | | 8 | | { |
| | | 9 | | public class AuthenticationFilterAttribute : ActionFilterAttribute |
| | | 10 | | { |
| | | 11 | | public override void OnActionExecuting(ActionExecutingContext context) |
| | 0 | 12 | | { |
| | 0 | 13 | | string authKey = context.HttpContext.Request.Headers["Authorization"].SingleOrDefault(); |
| | | 14 | | |
| | 0 | 15 | | if (string.IsNullOrWhiteSpace(authKey)) |
| | 0 | 16 | | throw new HttpException(HttpStatusCode.Unauthorized); |
| | 0 | 17 | | } |
| | | 18 | | } |
| | | 19 | | } |