public async Task Add_ShouldReturnOkWhenAdmin()
        {
            // Get JWT from Auth0
            var token = Auth0Helper.GetAdminAccountToken();

            var request = new HttpRequestMessage(HttpMethod.Post, "api/items/add");

            request.Headers.Add("Authorization", $"Bearer {token}");
            var requestData = new Item
            {
                Name        = "Item1",
                Description = "Description1",
                Price       = 9.99,
                Quantity    = 10
            };
            var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");

            request.Content = content;

            var response = await client.SendAsync(request);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            var responseContent = await response.Content.ReadAsStringAsync();

            var item = JsonConvert.DeserializeObject <Item>(responseContent);

            Assert.NotNull(item);
            Assert.Equal("Item1", item.Name);
            Assert.Equal("Description1", item.Description);
            Assert.Equal(9.99, item.Price);
            Assert.Equal(10, item.Quantity);
        }
        protected ControllerBaseTest()
        {
            var appFactory = new WebApplicationFactory <Startup>();

            Client = appFactory.CreateClient();
            var accessToken = Auth0Helper.GetAccessToken();

            _authenticationHeader = new AuthenticationHeaderValue("Bearer", accessToken);
        }
Esempio n. 3
0
        public ActionResult AccountProfile(ContentModel model)
        {
            var auth0Helper = new Auth0Helper();
            var user        = auth0Helper.GetAuth0User(CurrentUser.UserId);
            var customer    = new AccountProfileModel(model.Content)
            {
                UserId                 = user.UserId,
                EmailAddress           = user.Email,
                FirstName              = user.FirstName,
                LastName               = user.LastName,
                Phone                  = user.UserMetadata != null ? user.UserMetadata.Phone : "",
                SubscribedToNewsletter = user.UserMetadata != null?Convert.ToBoolean(user.UserMetadata.SubscribedToNewsletter) : false,
            };

            return(CurrentTemplate(customer));
        }
        public async Task Add_ShouldReturnForbiddenWhenNotAdmin()
        {
            // Get JWT from Auth0
            var token = Auth0Helper.GetTestAccountToken();

            var request = new HttpRequestMessage(HttpMethod.Post, "api/items/add");

            request.Headers.Add("Authorization", $"Bearer {token}");
            var requestData = new Item
            {
                Name        = "Item1",
                Description = "Description1",
                Price       = 9.99,
                Quantity    = 10
            };
            var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");

            request.Content = content;

            var response = await client.SendAsync(request);

            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
        public async Task <IActionResult> Put(Guid providerId)
        {
            _logger.LogInformation($"PUT - Approval request for provider: {providerId}");
            var existingProvider = await _repo.GetProviderAccountByIdAsync(providerId);

            if (existingProvider != null && existingProvider.Status.StatusText != Status.Approved)
            {
                Auth0Helper auth0 = _authHelperFactory.Create(Request);
                if (existingProvider.Email != auth0.Email)
                {
                    return(Forbid());
                }

                var authUser = await auth0.Client.Users.GetUsersByEmailAsync(auth0.Email);

                // Remove unapproved_provider role
                if (auth0.Roles.Contains(Auth0Helper.UnapprovedProviderRole))
                {
                    await auth0.RemoveRoleAsync(authUser[0].UserId, Auth0Helper.UnapprovedProviderRole);
                }

                // Add approved_provider
                await auth0.AddRoleAsync(authUser[0].UserId, Auth0Helper.ApprovedProviderRole);

                existingProvider.Status.StatusText = Status.Approved;
                await _repo.UpdateProviderAccountAsync(existingProvider);

                await _repo.SaveAsync();

                _logger.LogInformation($"Approval set to true for id: {providerId}");
                return(NoContent());
            }

            _logger.LogWarning($"Account already is approved, no change for id: {providerId}");
            return(NotFound());
        }
Esempio n. 6
0
 public CheckoutController()
 {
     _auth0Helper = new Auth0Helper();
 }
Esempio n. 7
0
 public TransactionControllerTest(TestServerFixture testServerFixture) : base(testServerFixture)
 {
     AdminToken = Auth0Helper.GetAdminAccountToken();
     TestToken  = Auth0Helper.GetTestAccountToken();
     Test2Token = Auth0Helper.GetTest2AccountToken();
 }
 public AuthenticationController(Auth0Helper _helper)
 {
     this._helper = _helper;
 }
Esempio n. 9
0
 public AccountPageController()
 {
     _auth0Helper = new Auth0Helper();
     _client      = _auth0Helper.CreateAuthenticationApiClientIfNotExists();
 }
Esempio n. 10
0
 public AuthenticateModel(IPublishedContent content) : base(content)
 {
     _auth0Helper = new Auth0Helper();
 }