Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 3b6592d

Browse files
committed
Remove Action filter and Authorize filter and create new Authentication filter to augment HttpContext. #12
1 parent e52a540 commit 3b6592d

File tree

6 files changed

+29
-47
lines changed

6 files changed

+29
-47
lines changed

src/SerilogWeb.Classic.WebApi/Classic/WebApi/PreApplicationStartModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static void Register()
99
{
1010
GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger),
1111
new WebApiExceptionLogger());
12-
GlobalConfiguration.Configuration.Filters.Add(new StoreWebApInfoInHttpContextActionFilter());
12+
GlobalConfiguration.Configuration.Filters.Add(new StoreWebApInfoInHttpContextAuthenticationFilter());
1313
}
1414
}
1515
}

src/SerilogWeb.Classic.WebApi/Classic/WebApi/StoreWebApInfoInHttpContextActionFilter.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using System.Web;
5+
using System.Web.Http;
6+
using System.Web.Http.Controllers;
7+
using System.Web.Http.Filters;
8+
9+
namespace SerilogWeb.Classic.WebApi
10+
{
11+
public class StoreWebApInfoInHttpContextAuthenticationFilter : IAuthenticationFilter
12+
{
13+
public bool AllowMultiple => false;
14+
15+
public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
16+
{
17+
context.ActionContext.StoreWebApInfoInHttpContext();
18+
await Task.FromResult(0);
19+
}
20+
21+
public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
22+
{
23+
await Task.FromResult(0);
24+
}
25+
}
26+
}

src/SerilogWeb.Classic.WebApi/Classic/WebApi/StoreWebApInfoInHttpContextAuthorizeFilter.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/SerilogWeb.Classic.WebApi/SerilogWeb.Classic.WebApi.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@
8181
<Compile Include="Classic\WebApi\Enrichers\WebApiRouteTemplateEnricher.cs" />
8282
<Compile Include="Classic\WebApi\HttpActionContextExtensions.cs" />
8383
<Compile Include="Classic\WebApi\PreApplicationStartModule.cs" />
84-
<Compile Include="Classic\WebApi\StoreWebApInfoInHttpContextAuthorizeFilter.cs" />
85-
<Compile Include="Classic\WebApi\StoreWebApInfoInHttpContextActionFilter.cs" />
84+
<Compile Include="Classic\WebApi\StoreWebApInfoInHttpContextAuthenticationFilter.cs" />
8685
<Compile Include="Classic\WebApi\WebApiExceptionLogger.cs" />
8786
<Compile Include="Classic\WebApi\WebApiRequestInfoKey.cs" />
8887
<Compile Include="Properties\AssemblyInfo.cs" />

test/SerilogWeb.Classic.WebApi.Test/Controllers/ValuesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public string ShouldThrowException()
2020

2121
[Route("api/values/shouldbeunauthorized")]
2222
[HttpGet]
23-
[StoreWebApInfoInHttpContextAuthorizeFilter]
23+
[Authorize]
2424
public void ShouldBeUnauthorized()
2525
{
2626
}

0 commit comments

Comments
 (0)