|
|
|
@ -7,9 +7,9 @@ using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure.Security;
|
|
|
|
|
|
|
|
|
|
public interface ITokenBuilder<TId> where TId : IEquatable<TId>
|
|
|
|
|
public interface ITokenBuilder
|
|
|
|
|
{
|
|
|
|
|
IList<Claim> GetClaimsFromUserContext(IUserContext<TId> userContext);
|
|
|
|
|
IList<Claim> GetClaimsFromUserContext<TId>(IUserContext<TId> userContext) where TId : IEquatable<TId>;
|
|
|
|
|
|
|
|
|
|
void SetUserContext(TokenValidatedContext context);
|
|
|
|
|
|
|
|
|
@ -20,9 +20,9 @@ public abstract class TokenBuilderBase<TId>(
|
|
|
|
|
JwtOptions jwtOptions,
|
|
|
|
|
JwtSecurityTokenHandler jwtSecurityTokenHandler,
|
|
|
|
|
IEncryptionService encryptionService)
|
|
|
|
|
: ITokenBuilder<TId> where TId : IEquatable<TId>
|
|
|
|
|
: ITokenBuilder where TId : IEquatable<TId>
|
|
|
|
|
{
|
|
|
|
|
public IList<Claim> GetClaimsFromUserContext(IUserContext<TId> userContext)
|
|
|
|
|
public virtual IList<Claim> GetClaimsFromUserContext<TId>(IUserContext<TId> userContext) where TId : IEquatable<TId>
|
|
|
|
|
{
|
|
|
|
|
var claims = new List<Claim>()
|
|
|
|
|
{
|
|
|
|
@ -39,7 +39,7 @@ public abstract class TokenBuilderBase<TId>(
|
|
|
|
|
return claims;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetUserContext(TokenValidatedContext context)
|
|
|
|
|
public virtual void SetUserContext(TokenValidatedContext context)
|
|
|
|
|
{
|
|
|
|
|
var userContext =
|
|
|
|
|
context.HttpContext.RequestServices.GetService(typeof(IUserContext<TId>)) as IUserContext<TId> ??
|
|
|
|
@ -55,7 +55,7 @@ public abstract class TokenBuilderBase<TId>(
|
|
|
|
|
userContext.RemoteIpAddress = context.HttpContext.GetRequestIp()!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JwtTokenInfo GenerateJwtTokenInfo(IReadOnlyCollection<Claim> claims)
|
|
|
|
|
public virtual JwtTokenInfo GenerateJwtTokenInfo(IReadOnlyCollection<Claim> claims)
|
|
|
|
|
{
|
|
|
|
|
var jwtToken = new JwtSecurityToken(
|
|
|
|
|
issuer: jwtOptions.Issuer,
|
|
|
|
|