Exemplo n.º 1
0
        public IActionResult Authorize()
        {
            var phoneNumber = HttpContext.TryGetConfirmedPhoneNumber();

            if (string.IsNullOrEmpty(phoneNumber))
            {
                throw new InvalidStateException("PhoneNumber should not be null or empty");
            }

            var phoneNumberValidationError = phoneNumberValidator.Validate(phoneNumber);

            if (phoneNumberValidationError != null)
            {
                throw new InvalidStateException("PhoneNumber should be valid");
            }

            var user  = usersRepository.GetOrCreate(phoneNumber);
            var token = tokenProvider.GetToken(user);

            return(Ok(new AuthorizationDto
            {
                UserId = user.Id,
                AuthorizationToken = token
            }));
        }