Created
March 15, 2016 16:53
-
-
Save ojhp/0a38819197f6d3f0d634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace SampleApi.Middleware | |
{ | |
using System; | |
using System.Threading.Tasks; | |
using Microsoft.AspNet.Builder; | |
using Microsoft.AspNet.Http; | |
using Microsoft.Extensions.Logging; | |
public class AuthenticationSuccessMarkerMiddleware | |
{ | |
private const string SuccessMarkerKey = AuthenticationExceptionHandlerMiddleware.SuccessMarkerKey; | |
private readonly RequestDelegate next; | |
private readonly ILogger<AuthenticationSuccessMarkerMiddleware> logger; | |
public AuthenticationSuccessMarkerMiddleware( | |
RequestDelegate next, | |
ILogger<AuthenticationSuccessMarkerMiddleware> logger) | |
{ | |
if (next == null) | |
{ | |
throw new ArgumentNullException(nameof(next)); | |
} | |
if (logger == null) | |
{ | |
throw new ArgumentNullException(nameof(logger)); | |
} | |
this.next = next; | |
this.logger = logger; | |
} | |
public Task Invoke(HttpContext context) | |
{ | |
// Set success marker to true | |
this.logger.LogInformation("Marking authentication as successful"); | |
context.Items[SuccessMarkerKey] = true; | |
// Continue pipeline | |
return this.next.Invoke(context); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment