moved service to separate project (Kontur developer said "WTF WHY ARE U STORING SERVICES IN INFRASTRUCTURE SLAVA D")

This commit is contained in:
Вячеслав 2025-04-18 14:12:00 +05:00
parent 147fb683f7
commit 41ff1555f8
11 changed files with 33 additions and 9 deletions

View file

@ -0,0 +1,31 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Microsoft.IdentityModel.Tokens;
using SurveyBackend.Core.Models;
namespace SurveyBackend.Services.Helpers;
public class TokenHelper
{
public static string GetAuthToken(User user)
{
var userId = user.Id.ToString();
var claims = new List<Claim>
{
new(ClaimTypes.NameIdentifier, userId)
};
var jwt = new JwtSecurityToken(
claims: claims,
issuer: AuthOptions.Issuer,
audience: AuthOptions.Audience,
expires: DateTime.UtcNow + AuthOptions.TokenLifetime,
signingCredentials: new SigningCredentials(AuthOptions.SymmetricSecurityKey, SecurityAlgorithms.HmacSha256)
);
var token = new JwtSecurityTokenHandler().WriteToken(jwt);
return token;
}
}