private string _generateToken(Guid id, string deviceNumber) { string token = null; IAuthContainerModel jwtModel = JwtTokenService.GetAuthModel(id.ToString(), deviceNumber); IAuthService authService = new JWTService(jwtModel.SecretKey); token = authService.GenerateToken(jwtModel); UserToken userTokenIsValid = _db.UserTokens.Where(e => e.DeviceNumber == deviceNumber).FirstOrDefault(); if (userTokenIsValid == null) { UserToken userToken = _db.UserTokens.Create(); userToken.Token = token; userToken.UserId = id; userToken.DeviceNumber = deviceNumber; _db.UserTokens.Add(userToken); _db.SaveChanges(); } else { userTokenIsValid.Token = token; userTokenIsValid.UpdatedAt = DateTime.UtcNow; _db.SaveChanges(); } return(token); }
public JWTAuthAttribute(string featureName) { _featureName = featureName; _objectService = new ObjectService <UserViewModel>(); _authModel = JwtTokenService.GetAuthModel(); _jwtService = new JWTService(_authModel.SecretKey); }
private string _generateRefreshToken(string id, string deviceNumber) { IAuthContainerModel jwtModel = JwtTokenService.GetAuthModel(id, deviceNumber); jwtModel.SecretKey = _secretKeyRefreshToken; jwtModel.ExpireMinutes = 13; IAuthService authService = new JWTService(jwtModel.SecretKey); return(authService.GenerateToken(jwtModel)); }