public void GenerateRefreshAndUpdateUser(T login, Action <string> refreshHandler) { var refreshToken = tokenService.GenerateRefreshToken(); JwtRefreshToken tokenResponse = broker.SendBroker <JwtRefreshToken>(new JwtRefreshToken() { RefreshToken = refreshToken, UserName = login.UserName }); refreshHandler.Invoke(!string.IsNullOrEmpty(tokenResponse.Code) ? refreshToken : string.Empty); // refreshHandler.Invoke(refreshToken); }
public TokenVO ValidateCredentials(UserVO userCredentials) { // Validando se o usuário existe var user = _repo.ValidateCredentials(userCredentials); if (user == null) { return(null); } // Definindo as claims var claims = new List <Claim>(); claims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N"))); claims.Add(new Claim(JwtRegisteredClaimNames.UniqueName, userCredentials.Username)); // Definição do access token e refresh token var accessToken = _tokenService.GenerateAccessToken(claims); // Quando o access token expirar, este será usado var refreshToken = _tokenService.GenerateRefreshToken(); user.RefreshToken = refreshToken; user.RefreshTokenExpiryTime = DateTime.Now.AddDays(_tokenConfig.DaysToExpire); _repo.RefreshUserInfo(user); var createDate = DateTime.Now; var expirationDate = createDate.AddMinutes(_tokenConfig.Minutes); return(new TokenVO( true, createDate.ToString(DATE_FORMAT), expirationDate.ToString(DATE_FORMAT), accessToken, refreshToken )); }