示例#1
0
        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;
            }
        }
示例#2
0
        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);
        }
示例#3
0
 public async Task <IList <Claim> > GetClaimsForUser(MarinAppUser user)
 {
     return(await _userManager.GetClaimsAsync(user));
 }
示例#4
0
 public async Task <IdentityResult> ResetPasswordAsync(MarinAppUser user, string code, string newPassword)
 {
     return(await _userManager.ResetPasswordAsync(user, code, newPassword));
 }
示例#5
0
 public async Task <IdentityResult> ConfirmEmailAsync(MarinAppUser user, string code)
 {
     return(await _userManager.ConfirmEmailAsync(user, code));
 }
示例#6
0
 public string CreatePasswordResetToken(MarinAppUser user)
 {
     return(_userManager.GeneratePasswordResetTokenAsync(user).Result);
 }
示例#7
0
 public string CreateEmailConfirmationToken(MarinAppUser user)
 {
     return(_userManager.GenerateEmailConfirmationTokenAsync(user).Result);
 }
示例#8
0
 public async Task <bool> IsEmailConfirmedAsync(MarinAppUser user)
 {
     return(await _userManager.IsEmailConfirmedAsync(user));
 }