using System.Collections.Generic; using System.Security.Claims; using IdentityModel; using Kyoo.Models; namespace Kyoo.Authentication { /// /// Extension methods. /// public static class Extensions { /// /// Get claims of an user. /// /// The user concerned /// The list of claims the user has public static ICollection GetClaims(this User user) { return new[] { new Claim(JwtClaimTypes.Subject, user.ID.ToString()), new Claim(JwtClaimTypes.Name, user.Username), new Claim(JwtClaimTypes.Picture, $"api/account/picture/{user.Slug}") }; } /// /// Convert a user to a ClaimsPrincipal. /// /// The user to convert /// A ClaimsPrincipal representing the user public static ClaimsPrincipal ToPrincipal(this User user) { ClaimsIdentity id = new (user.GetClaims()); return new ClaimsPrincipal(id); } } }