medicalHistory: deletion when patient is deleted
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Application.Services.Jwt;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
public class JwtService : IJwtService
|
||||
{
|
||||
private readonly string _secretKey;
|
||||
private readonly string _issuer;
|
||||
private readonly string _audience;
|
||||
private readonly double _expiryMinutes;
|
||||
private readonly string _issuer;
|
||||
private readonly string _secretKey;
|
||||
|
||||
public JwtService(IConfiguration configuration)
|
||||
{
|
||||
@@ -34,13 +33,14 @@ public class JwtService : IJwtService
|
||||
Expires = DateTime.UtcNow.AddMinutes(_expiryMinutes),
|
||||
Issuer = _issuer,
|
||||
Audience = _audience,
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
SigningCredentials =
|
||||
new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
|
||||
|
||||
public bool ValidateJwtToken(string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
@@ -58,9 +58,9 @@ public class JwtService : IJwtService
|
||||
ValidateAudience = true,
|
||||
ValidIssuer = _issuer,
|
||||
ValidAudience = _audience,
|
||||
ClockSkew = TimeSpan.Zero,
|
||||
}, out SecurityToken validatedToken);
|
||||
|
||||
ClockSkew = TimeSpan.Zero
|
||||
}, out var validatedToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
@@ -68,20 +68,14 @@ public class JwtService : IJwtService
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string RefreshToken(string token)
|
||||
{
|
||||
var principal = ValidateTokenAndGetPrincipal(token);
|
||||
if (principal == null)
|
||||
{
|
||||
throw new SecurityTokenException("Invalid token.");
|
||||
}
|
||||
if (principal == null) throw new SecurityTokenException("Invalid token.");
|
||||
|
||||
var emailClaim = principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
|
||||
if (emailClaim == null)
|
||||
{
|
||||
throw new SecurityTokenException("Token does not contain an email claim.");
|
||||
}
|
||||
if (emailClaim == null) throw new SecurityTokenException("Token does not contain an email claim.");
|
||||
|
||||
return GenerateJwtToken(emailClaim.Value);
|
||||
}
|
||||
@@ -100,7 +94,7 @@ public class JwtService : IJwtService
|
||||
ValidateAudience = true,
|
||||
ValidIssuer = _issuer,
|
||||
ValidAudience = _audience,
|
||||
ClockSkew = TimeSpan.Zero,
|
||||
ClockSkew = TimeSpan.Zero
|
||||
}, out _);
|
||||
|
||||
return principal;
|
||||
@@ -111,5 +105,4 @@ public class JwtService : IJwtService
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user