public virtual UserJwtTokenDto GenerateUserJwtToken(LoginDto userDto) { var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Key)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); var claims = new[] { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.UniqueName, userDto.UserName), new Claim(JwtRegisteredClaimNames.AuthTime, DateTime.Now.ToString("MM/dd/yyyy")) }; var token = new JwtSecurityToken( issuer: Issuer, audience: Issuer, claims: claims, expires: DateTime.Now.AddMinutes(ExpirationInMinutes), signingCredentials: credentials ); var encodeToken = new JwtSecurityTokenHandler().WriteToken(token); var userJwtTokenDto = new UserJwtTokenDto { UserName = userDto.UserName, AccessToken = encodeToken, AccessTokenExpiresDateTime = DateTime.Now.AddMinutes(ExpirationInMinutes), TokenPlatform = userDto.Platform }; return(userJwtTokenDto); }
public virtual async Task <UserJwtToken> SaveUserJwtTokenAsync(UserJwtTokenDto userJwtTokenDto) { var tokenHash = HashToken(userJwtTokenDto.AccessToken); var userJwtToken = new UserJwtToken { AccessTokenHash = tokenHash, AccessTokenExpiresDateTime = userJwtTokenDto.AccessTokenExpiresDateTime, TokenPlatform = userJwtTokenDto.TokenPlatform, UserId = await UserService.GetUserIdByUserNameAsync(userJwtTokenDto.UserName) }; return(await UserJwtTokenRepository.AddAsync(userJwtToken)); }
public virtual async Task <UserJwtToken> SaveJwtTokenAsync(UserJwtTokenDto userJwtTokenDto) { var accessToken = await HashToken(userJwtTokenDto.AccessToken); var userJwtToken = new UserJwtToken { AccessToken = accessToken, AccessTokenExpireDateTime = userJwtTokenDto.AccessTokenExpireDateTime, Platform = userJwtTokenDto.TokenPlatform, UserId = await UserService.GetUserIdAsync(userJwtTokenDto.Username) }; return(await UserJwtTokenRepository.AddAsync(userJwtToken)); }