protected override void OnLoad(EventArgs e) { base.OnLoad(e); _signInService.RefreshTokenAsync().GetAwaiter().GetResult(); UserAuthorized(_signInService.IsAuthorized); RefreshMenuItems(); }
public async void RefreshTokenAcceptedCases(string username, string email, string password) { // Arrange var user = new User { Name = username, Email = email }; user.PasswordHash = _userService.PasswordHasher.Hash(password); await _userService.CreateAsync(user); // Act var result1 = await _signInService.SignInAsync(username, password, new UserLogin { }); await Task.Delay(TimeSpan.FromSeconds(1)); // wait until token expired var result2 = await _signInService.RefreshTokenAsync(result1.Outcome.AccessToken, result1.Outcome.RefreshToken); await Task.Delay(TimeSpan.FromSeconds(1)); // wait until token expired var result3 = await _signInService.RefreshTokenAsync(result2.Outcome.AccessToken, result2.Outcome.RefreshToken); await Task.Delay(TimeSpan.FromSeconds(1)); // wait until token expired var result4 = await _signInService.RefreshTokenAsync(result3.Outcome.AccessToken, result3.Outcome.RefreshToken); await Task.Delay(TimeSpan.FromSeconds(1)); // wait until token expired var result5 = await _signInService.RefreshTokenAsync(result4.Outcome.AccessToken, result4.Outcome.RefreshToken); await Task.Delay(TimeSpan.FromSeconds(1)); // wait until token expired // Assert Assert.Equal(GResult.Success, result1); Assert.Equal(GResult.Success, result5); Assert.NotNull(result5.Outcome); Assert.NotNull(result5.Outcome.AccessToken); Assert.NotEmpty(result5.Outcome.AccessToken); Assert.NotEqual(result1.Outcome.AccessToken, result5.Outcome.AccessToken); Assert.Equal(result1.Outcome.RefreshToken, result5.Outcome.RefreshToken); // Before refresh token requires an update, must be equal // here refresh token will be updated var result6 = await _signInService.RefreshTokenAsync(result5.Outcome.AccessToken, result5.Outcome.RefreshToken); // Assert Assert.Equal(GResult.Success, result1); Assert.Equal(GResult.Success, result6); Assert.NotNull(result6.Outcome); Assert.NotNull(result6.Outcome.AccessToken); Assert.NotEmpty(result6.Outcome.AccessToken); Assert.NotEqual(result1.Outcome.AccessToken, result6.Outcome.AccessToken); Assert.NotEqual(result1.Outcome.RefreshToken, result6.Outcome.RefreshToken);// after updating refresh token, must be not equal }
public async Task <GResult <TokenModel> > HandleAsync(RefreshTokenCommand command) { var result = await _signInService.RefreshTokenAsync(command.AccessToken, command.RefreshToken); return(result); }