1
0
mirror of https://github.com/bitwarden/server synced 2026-01-06 18:43:36 +00:00

Move claims issuance and security stamp checks out into profile service. moved context sets out of identity implementations and into get methods.

This commit is contained in:
Kyle Spearrin
2017-01-24 22:15:21 -05:00
parent cb5419aca8
commit 8a83600e52
9 changed files with 153 additions and 65 deletions

View File

@@ -0,0 +1,33 @@
using Bit.Core;
using Microsoft.AspNetCore.Http;
using System.Linq;
using System.Threading.Tasks;
namespace Bit.Api.Middleware
{
public class CurrentContextMiddleware
{
private readonly RequestDelegate _next;
public CurrentContextMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext, CurrentContext currentContext)
{
if(httpContext.User != null)
{
var securityStampClaim = httpContext.User.Claims.FirstOrDefault(c => c.Type == "device");
currentContext.DeviceIdentifier = securityStampClaim?.Value;
}
if(currentContext.DeviceIdentifier == null && httpContext.Request.Headers.ContainsKey("Device-Identifier"))
{
currentContext.DeviceIdentifier = httpContext.Request.Headers["Device-Identifier"];
}
await _next.Invoke(httpContext);
}
}
}