accounts + argon2 migration

This commit is contained in:
2025-05-16 09:04:03 -04:00
parent 12a28f00b1
commit 3ac1fbcd8e
6 changed files with 104 additions and 3 deletions

35
AobaCore/Models/User.cs Normal file
View File

@@ -0,0 +1,35 @@
using Microsoft.IdentityModel.Tokens;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace AobaCore.Models;
public class User
{
[BsonId]
public ObjectId Id { get; set; }
public required string Username { get; set; }
public required string PasswordHash { get; set; }
public required string Role { get; set; }
public bool IsArgon { get; set; }
public ObjectId[] ApiKeys { get; set; } = [];
public List<ObjectId> RegTokens { get; set; } = [];
public ClaimsIdentity GetIdentity()
{
var id = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, Id.ToString()),
new Claim(ClaimTypes.Name, Username),
});
if (Role != null)
id.AddClaim(new Claim(ClaimTypes.Role, Role));
return id;
}
}