25 lines
862 B
C#
25 lines
862 B
C#
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
public static class TestAuthContext
|
|
{
|
|
public static void AsNurse(
|
|
IServiceProvider services,
|
|
Guid? userId = null,
|
|
string displayName = "Test Nurse")
|
|
{
|
|
var accessor = services.GetRequiredService<IHttpContextAccessor>();
|
|
var context = new DefaultHttpContext();
|
|
var claims = new[]
|
|
{
|
|
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
|
new Claim(ClaimTypes.Name, "test-nurse"),
|
|
new Claim("display_name", displayName),
|
|
new Claim("clinical_role", "NURSE"),
|
|
};
|
|
context.User = new ClaimsPrincipal(new ClaimsIdentity(claims, TestingAuthHandler.SchemeName));
|
|
accessor.HttpContext = context;
|
|
}
|
|
}
|