Exemplo n.º 1
0
        public async Task GetManagementClientAsync_ShouldSucceed()
        {
            var auth0FactoryOptions = new Auth0FactoryOptions
            {
                Domain           = Environment.GetEnvironmentVariable("E2E_Domain"),
                ClientId         = Environment.GetEnvironmentVariable("E2E_ClientId"),
                ClientSecret     = Environment.GetEnvironmentVariable("E2E_ClientSecret"),
                ReuseAccessToken = false
            };

            if (auth0FactoryOptions.Domain == null ||
                auth0FactoryOptions.ClientId == null ||
                auth0FactoryOptions.ClientSecret == null)
            {
                Assert.Fail("Environment variables are not configured correctly.");
            }

            var accessTokenFactory = new Auth0AccessTokenFactory(auth0FactoryOptions);
            var clientFactory      = new Auth0ClientFactory(auth0FactoryOptions, accessTokenFactory);
            var client             = await clientFactory.GetManagementApiClientAsync();

            var getUsersRequest = new GetUsersRequest();
            var users           = await client.Users.GetAllAsync(getUsersRequest);

            Assert.IsNotNull(users);
            Assert.AreEqual(0, users.Count);
        }
        public void Initialize()
        {
            options = new Auth0FactoryOptions()
            {
                Domain           = Guid.NewGuid().ToString(),
                ClientId         = Guid.NewGuid().ToString(),
                ClientSecret     = Guid.NewGuid().ToString(),
                ReuseAccessToken = false
            };

            mockHttpMessageHandler = new MockHttpMessageHandler();
            accessTokenFactory     = null; // Reset factory
        }
        public async Task GetAccessTokenAsync_ProcessRequestResponseCorrectly()
        {
            // Arrange
            var accessToken = Guid.NewGuid().ToString();

            mockHttpMessageHandler
            .When(HttpMethod.Post, $"https://{options.Domain}/oauth/token")
            .Respond(request => CreateResponseMessage(accessToken, 0));

            accessTokenFactory = new Auth0AccessTokenFactory(options, mockHttpMessageHandler.ToHttpClient());

            // Act
            var actualAccessToken = await accessTokenFactory.GetAccessTokenAsync();

            // Assert
            mockHttpMessageHandler.VerifyNoOutstandingRequest();
            Assert.AreEqual(accessToken, actualAccessToken);
        }
        public async Task GetAccessTokenAsync_WithTokenReuse_ShouldOnlyRequestOnce()
        {
            // Arrange
            mockHttpMessageHandler
            .Expect(HttpMethod.Post, "*")
            .Respond(request => CreateResponseMessage(string.Empty, 3600));

            options.ReuseAccessToken = true;

            accessTokenFactory = new Auth0AccessTokenFactory(options, mockHttpMessageHandler.ToHttpClient());

            // Act
            await accessTokenFactory.GetAccessTokenAsync();

            await accessTokenFactory.GetAccessTokenAsync();

            // Assert
            mockHttpMessageHandler.VerifyNoOutstandingRequest();
        }