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:
33
src/Api/Middleware/CurrentContextMiddleware.cs
Normal file
33
src/Api/Middleware/CurrentContextMiddleware.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user