mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
26 lines
594 B
C#
26 lines
594 B
C#
using System.Collections.Generic;
|
|
using System.Security.Claims;
|
|
using IdentityModel;
|
|
using Kyoo.Models;
|
|
|
|
namespace Kyoo.Authentication
|
|
{
|
|
/// <summary>
|
|
/// Extension methods.
|
|
/// </summary>
|
|
public static class Extensions
|
|
{
|
|
public static ClaimsPrincipal ToPrincipal(this User user)
|
|
{
|
|
List<Claim> claims = new()
|
|
{
|
|
new Claim(JwtClaimTypes.Subject, user.ID.ToString()),
|
|
new Claim(JwtClaimTypes.Name, user.Username),
|
|
new Claim(JwtClaimTypes.Picture, $"api/account/picture/{user.Slug}")
|
|
};
|
|
|
|
ClaimsIdentity id = new (claims);
|
|
return new ClaimsPrincipal(id);
|
|
}
|
|
}
|
|
} |