Skip to content

Instantly share code, notes, and snippets.

@ojhp
Created March 15, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojhp/0a38819197f6d3f0d634 to your computer and use it in GitHub Desktop.
Save ojhp/0a38819197f6d3f0d634 to your computer and use it in GitHub Desktop.
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