-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiKeyActionFilter.cs
30 lines (24 loc) · 1.06 KB
/
ApiKeyActionFilter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
public class ApiKeyActionFilter
: IAsyncActionFilter
{
Task IAsyncActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
throw new NotImplementedException();
// if (context.HttpContext.Request.Headers.TryGetValue("X-ApiKey", out Microsoft.Extensions.Primitives.StringValues apiKeyHeaderValues))
// {
// var apiKeyHeaderValue = apiKeyHeaderValues.First();
// // ... your authentication logic here ...
// var username = (apiKeyHeaderValue == "12345" ? "Maarten" : "OtherUser");
// var usernameClaim = new Claim(ClaimTypes.Name, username);
// var identity = new ClaimsIdentity(new[] {usernameClaim}, "ApiKey");
// var principal = new ClaimsPrincipal(identity);
// context.HttpContext.User = principal;
// }
// return base.SendAsync(request, cancellationToken);
}
}