public void SetFrom(IJokJaBreIdentityModel model) { if (model is TIdentityModel identityModel) { SetFrom(identityModel); } }
public void SetTo(IJokJaBreIdentityModel obj) { if (obj is TIdentityModel model) { SetTo(model); } }
public static string GetToken(this IJokJaBreIdentityModel user, IConfiguration configuration) { if (user == null) { return(null); } var claim = new[] { new Claim(JwtRegisteredClaimNames.Sub, user.Username) }; var signinKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(configuration["JokJaBre:Auth:SigningKey"])); int expiryInMinutes = Convert.ToInt32(configuration["JokJaBre:Auth:ExpiresIn"]); var token = new JwtSecurityToken( claims: claim, issuer: configuration["JokJaBre:Auth:Site"], audience: configuration["JokJaBre:Auth:Site"], expires: DateTime.UtcNow.AddMinutes(expiryInMinutes), signingCredentials: new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256) ); return(new JwtSecurityTokenHandler().WriteToken(token)); }
public static string HashPassword(this IJokJaBreIdentityModel user, IConfiguration configuration, int iterationCount = 10000) { // generate a 128-bit salt using a secure PRNG byte[] salt = Encoding.Unicode.GetBytes(configuration["JokJaBre:Salt"]); // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations) string hashed = Convert.ToBase64String( KeyDerivation.Pbkdf2( password: user.Password, salt: salt, prf: KeyDerivationPrf.HMACSHA256, iterationCount: iterationCount, numBytesRequested: 256 / 8)); user.Password = hashed; return(hashed); }
public static TResponse ToIdentityResponse <TResponse>(this IJokJaBreIdentityModel model, IConfiguration configuration) where TResponse : IJokJaBreIdentityResponse { if (model == null) { return(default);