Closing applications

This commit is contained in:
2024-09-08 15:14:07 +03:00
parent c128349f3b
commit 11b28359dd
6 changed files with 113 additions and 47 deletions

View File

@@ -0,0 +1,6 @@
using BlazorWebAssemblyVisaApiClient.Common;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions
{
public class UnknownRoleException() : BlazorClientException("Unknown user role");
}

View File

@@ -1,12 +1,14 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
{
public class UserDataProvider(Client client) : IUserDataProvider
{
private static readonly JwtSecurityTokenHandler tokenHandler = new ();
private readonly static JwtSecurityTokenHandler tokenHandler = new ();
private readonly static string[] knownRoles = ["Applicant", "ApprovingAuthority", "Admin"];
public async Task<ApplicantModel> GetApplicant()
{
@@ -23,6 +25,11 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
var token = tokenHandler.ReadJwtToken(client.AuthToken.Token);
var role = token.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Role)?.Value;
if (!knownRoles.Contains(role))
{
throw new UnknownRoleException();
}
return role;
}
}