38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
|
|
using System.Security.Claims;
|
||
|
|
|
||
|
|
namespace backend.Tests.Utilities;
|
||
|
|
|
||
|
|
public static class TestUserClaims
|
||
|
|
{
|
||
|
|
public static ClaimsPrincipal CreateOrganizer(Guid? userId = null, string email = "organizer@example.com")
|
||
|
|
{
|
||
|
|
var claims = new List<Claim>
|
||
|
|
{
|
||
|
|
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
||
|
|
new Claim(ClaimTypes.Email, email),
|
||
|
|
new Claim(ClaimTypes.Role, "Organizer")
|
||
|
|
};
|
||
|
|
|
||
|
|
var identity = new ClaimsIdentity(claims, "TestAuthType");
|
||
|
|
return new ClaimsPrincipal(identity);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static ClaimsPrincipal CreateParticipant(Guid? userId = null, string email = "participant@example.com")
|
||
|
|
{
|
||
|
|
var claims = new List<Claim>
|
||
|
|
{
|
||
|
|
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
||
|
|
new Claim(ClaimTypes.Email, email),
|
||
|
|
new Claim(ClaimTypes.Role, "Participant")
|
||
|
|
};
|
||
|
|
|
||
|
|
var identity = new ClaimsIdentity(claims, "TestAuthType");
|
||
|
|
return new ClaimsPrincipal(identity);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static ClaimsPrincipal CreateUnauthenticated()
|
||
|
|
{
|
||
|
|
return new ClaimsPrincipal(new ClaimsIdentity());
|
||
|
|
}
|
||
|
|
}
|