mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Registration rework
+ InvitesRepository + AdminsRepository + rework jwt
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Govor.API.Services.Authentication.Interfaces;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Core.Repositories.Admins;
|
||||
using Govor.Core.Repositories.Invaites;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
@@ -11,14 +13,22 @@ namespace Govor.API.Services.Authentication;
|
||||
public class JwtService : IJwtService
|
||||
{
|
||||
private JwtOption _jwtOption;
|
||||
private IInvitesRepository _invitesRepository;
|
||||
|
||||
public JwtService(IOptions<JwtOption> options)
|
||||
{
|
||||
_jwtOption = options.Value;
|
||||
}
|
||||
|
||||
public string GenerateJwtToken(User user)
|
||||
{
|
||||
Claim[] claims = [new("userID", user.Id.ToString())];
|
||||
var invite = _invitesRepository.GetByIdAsync(user.InviteId).Result;
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim("userID", user.Id.ToString()),
|
||||
new Claim(ClaimTypes.Role, invite.IsAdmin ? "Admin" : "User", ClaimValueTypes.String)
|
||||
};
|
||||
|
||||
var singing = new SigningCredentials(
|
||||
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtOption.SecretKeу)),
|
||||
|
||||
Reference in New Issue
Block a user