using Microsoft.IdentityModel.Tokens; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; namespace RecRoomArchive.Services { public class AuthorizationService { private static readonly string Key = "hello diddy blud. you need to replace me. or not, really it doesnt matter...I forgot how long a token like this has to be so I'm just gonna run my mouth. Hi. This is RecRoomArchive. You may wonder why we have JWT tokens in a localhost server, and that's because 2020 requires it and stuff. and 2019. Especially 2021. I wonder if I will be doing 2021 or not..."; public string GenerateToken(ulong id) { JwtSecurityTokenHandler handler = new(); List claims = new List() { new(ClaimTypes.NameIdentifier, id.ToString()), new(ClaimTypes.Role, "gameClient") }; SecurityTokenDescriptor tokenDescriptor = new() { Subject = new ClaimsIdentity(claims), Expires = DateTime.UtcNow.Add(TimeSpan.FromHours(12)), Issuer = "https://recroomarchive.org/", SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Key)), SecurityAlgorithms.HmacSha256) }; JwtSecurityToken token = handler.CreateJwtSecurityToken(tokenDescriptor); return handler.WriteToken(token); } } }