public string GenerateJwtToken(MarinAppUser user, IList <Claim> identityClaims) { identityClaims.Add(new Claim(JwtRegisteredClaimNames.Sub, user.Email)); identityClaims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); var token = new JwtSecurityToken ( issuer: _configuration["JwtIssuer"], audience: _configuration["JwtIssuer"], claims: identityClaims, expires: DateTime.UtcNow.AddHours(1), notBefore: DateTime.UtcNow, signingCredentials: new SigningCredentials(new SymmetricSecurityKey (Encoding.UTF8.GetBytes(_configuration["JwtKey"])), SecurityAlgorithms.HmacSha256) ); try { return(new JwtSecurityTokenHandler().WriteToken(token)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task <IdentityResult> CreateUser(string firstName, string lastName, string email, string password) { var appUser = new MarinAppUser(email, firstName, lastName); var result = await _userManager.CreateAsync(appUser, password); if (!result.Succeeded) { return(result); } await _userManager.AddClaimAsync(appUser, new Claim("UserId", appUser.Id)); await _userManager.UpdateAsync(appUser); return(result); }
public async Task <IList <Claim> > GetClaimsForUser(MarinAppUser user) { return(await _userManager.GetClaimsAsync(user)); }
public async Task <IdentityResult> ResetPasswordAsync(MarinAppUser user, string code, string newPassword) { return(await _userManager.ResetPasswordAsync(user, code, newPassword)); }
public async Task <IdentityResult> ConfirmEmailAsync(MarinAppUser user, string code) { return(await _userManager.ConfirmEmailAsync(user, code)); }
public string CreatePasswordResetToken(MarinAppUser user) { return(_userManager.GeneratePasswordResetTokenAsync(user).Result); }
public string CreateEmailConfirmationToken(MarinAppUser user) { return(_userManager.GenerateEmailConfirmationTokenAsync(user).Result); }
public async Task <bool> IsEmailConfirmedAsync(MarinAppUser user) { return(await _userManager.IsEmailConfirmedAsync(user)); }