Ejemplo n.º 1
0
        public async Task Using_explicit_configuration_with_multiple_client_config_should_succeed()
        {
            var handler = new NetworkHandler();

            void options(AccessTokenManagementOptions o)
            {
                o.Client.Clients.Add("test1", new ClientCredentialsTokenRequest
                {
                    Address  = "https://test1",
                    ClientId = "test1"
                });

                o.Client.Clients.Add("test2", new ClientCredentialsTokenRequest
                {
                    Address  = "https://test2",
                    ClientId = "test2"
                });
            }

            var service = Setup.Collection(options, handler)
                          .BuildServiceProvider()
                          .GetRequiredService <IAccessTokenManagementService>();


            var result = await service.GetClientAccessTokenAsync("test1");

            handler.Address.Should().Be(new Uri("https://test1"));

            result = await service.GetClientAccessTokenAsync("test2");

            handler.Address.Should().Be(new Uri("https://test2"));
        }
Ejemplo n.º 2
0
        public async Task Using_default_configuration_with_multiple_client_config_should_fail()
        {
            var handler = new NetworkHandler();

            void options(AccessTokenManagementOptions o)
            {
                o.Client.Clients.Add("test1", new ClientCredentialsTokenRequest
                {
                    Address  = "https://test1",
                    ClientId = "test1"
                });

                o.Client.Clients.Add("test2", new ClientCredentialsTokenRequest
                {
                    Address  = "https://test2",
                    ClientId = "test2"
                });
            }

            var service = Setup.Collection(options, handler)
                          .BuildServiceProvider()
                          .GetRequiredService <IAccessTokenManagementService>();


            Func <Task> act = async() => { var result = await service.GetClientAccessTokenAsync(); };

            await act.Should().ThrowAsync <InvalidOperationException>();
        }
Ejemplo n.º 3
0
        public async Task Using_default_configuration_should_pass_client_parameters()
        {
            var handler = new NetworkHandler();

            void options(AccessTokenManagementOptions o)
            {
                o.Client.Clients.Add("test", new ClientCredentialsTokenRequest
                {
                    Address    = "https://test",
                    ClientId   = "test",
                    Parameters = new Dictionary <string, string> {
                        { "audience", "test123" }
                    }
                });
            }

            var service = Setup.Collection(options, handler)
                          .BuildServiceProvider()
                          .GetRequiredService <IAccessTokenManagementService>();

            var result = await service.GetClientAccessTokenAsync();

            var requestContent = await handler.Content.ReadAsStringAsync();

            requestContent.Should().Contain("audience=test123");
        }
        public async Task Using_default_configuration_with_wrong_scheme_or_explicit_client_config_should_fail()
        {
            var service = Setup.Collection()
                          .AddTransient(p => p.GetRequiredService <ITokenClientConfigurationService>() as DefaultTokenClientConfigurationService)
                          .BuildServiceProvider()
                          .GetRequiredService <DefaultTokenClientConfigurationService>();

            Func <Task> act = async() => { var settings = await service.GetOpenIdConnectSettingsAsync("invalid"); };

            await act.Should().ThrowAsync <InvalidOperationException>();
        }
        public async Task Using_default_configuration_with_single_client_config_should_succeed()
        {
            var handler = new NetworkHandler();

            void options(AccessTokenManagementOptions o)
            {
                o.Client.Clients.Add("test", new IdentityModel.Client.TokenClientOptions
                {
                    Address  = "https://test",
                    ClientId = "test"
                });
            }

            var service = Setup.Collection(options, handler)
                          .BuildServiceProvider()
                          .GetRequiredService <IAccessTokenManagementService>();

            var result = await service.GetClientAccessTokenAsync();

            handler.Address.Should().Be(new Uri("https://test"));
        }