public async Task <TokenDto> RefreshAccessTokenAsync(string refreshToken, string remoteIpAddress) { var command = new RefreshAccessToken.Command { RefreshToken = refreshToken, RemoteIpAddress = remoteIpAddress }; var token = await _mediator.Send(command); await RevokeRefreshTokenAsync(refreshToken, remoteIpAddress); return(_mapper.Map <TokenDto>(token)); }
public void Should_Throw_AuthenticationException_If_RefreshToken_Is_Expired() { // Arrange var command = new RefreshAccessToken.Command { RefreshToken = "staff_expired_refresh_token", RemoteIpAddress = "127.0.0.1", }; _jwtGenerator.CreateTokensAsync(Arg.Any <User>(), Arg.Any <string>()).Returns("newToken"); // Act Func <Task <string> > func = async() => await _handler.Handle(command, new CancellationToken()); // Assert func.Should().Throw <AuthenticationException>(); }
public void Should_Throw_AuthorizationException_If_RefreshToken_Is_Accessed_With_Different_Ip() { // Arrange var command = new RefreshAccessToken.Command { RefreshToken = "performer_valid_refresh_token", RemoteIpAddress = "127.0.0.2", }; _jwtGenerator.CreateTokensAsync(Arg.Any <User>(), Arg.Any <string>()).Returns("newToken"); // Act Func <Task <string> > func = async() => await _handler.Handle(command, new CancellationToken()); // Assert func.Should().Throw <AuthorizationException>(); }
public async Task Should_Refresh_AccessToken() { // Arrange var command = new RefreshAccessToken.Command { RefreshToken = "performer_valid_refresh_token", RemoteIpAddress = "127.0.0.1", }; _jwtGenerator.CreateTokensAsync(Arg.Any <User>(), Arg.Any <string>()).Returns("newToken"); // Act string result = await _handler.Handle(command, new CancellationToken()); // Assert result.Should().BeEquivalentTo("newToken"); }