Exemplo n.º 1
0
        public async void Register_ValidUserInfo_Success()
        {
            var result = await usersController.Register(validRegisterRquest);

            var okResult     = result.Should().BeOfType <OkObjectResult>().Subject;
            var authResponse = okResult.Value.Should().BeAssignableTo <AuthenticateResponse>().Subject;

            authResponse.AccessToken.Should().NotBeNullOrEmpty();
            Assert.NotNull(jwtTokenHelper.ValidateToken(authResponse.AccessToken));
            authResponse.RefreshToken.Should().NotBeNullOrEmpty();
            authResponse.User.Should().NotBeNull();
            authResponse.User.Name.Should().Be(validRegisterRquest.Name);
            authResponse.User.Email.Should().Be(validRegisterRquest.Email);
            Assert.True(Utilities.ValidatePassword(validRegisterRquest.Password, authResponse.User.Password));

            authResponse.User.Role.Should().Be(Entities.Role.User);
            authResponse.User.Type.Should().Be(AccountType.Local);
            authResponse.User.UpdatedOn.Should().BeCloseTo(DateTime.UtcNow, TWO_SECONDS_IN_MILLIONSECONDS);
            authResponse.User.CreatedOn.Should().BeCloseTo(DateTime.UtcNow, TWO_SECONDS_IN_MILLIONSECONDS);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAuthenticationInfo(AuthInfoRequest request)
        {
            try
            {
                var claim = jwtTokenHelper.ValidateToken(request.AccessToken);

                var user = await databaseService.GetUserAsync(claim.Value);

                var response = new AuthenticateResponse(user, jwtTokenHelper.GenerateJwtToken(user));

                return(Ok(response));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }