public async Task CreateTokenFactoryReturnsToken(
            TestIdentityServer4TestServerFactory serverFactory,
            TestIdentityServer4TestClientFactory clientFactory,
            string clientId,
            string clientSecret,
            string apiResourceName,
            string apiResourceDisplayName,
            int lifetime)
        {
            using (var server = await serverFactory
                                .WithLogging(new XUnitLoggerFactory(this.output))
                                .WithApiResource(new ApiResource(apiResourceName, apiResourceDisplayName))
                                .WithClient(new Client
            {
                ClientId = clientId,
                ClientSecrets = new List <Secret> {
                    new Secret(clientSecret.Sha256())
                },
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                AllowedScopes = new List <string> {
                    apiResourceName
                },
            }).Create())
            {
                var tokenFactory = server.CreateTokenFactory();
                var tokenResult  = await tokenFactory.CreateToken(
                    lifetime : lifetime,
                    claims : new List <Claim>());

                Assert.NotNull(tokenResult.Token);
            }
        }
        public async Task RequestClientCredentialsReturnsAcccessToken(
            TestIdentityServer4TestServerFactory serverFactory,
            TestIdentityServer4TestClientFactory clientFactory,
            string clientId,
            string clientSecret,
            string apiResourceName,
            string apiResourceDisplayName)
        {
            using (var server = await serverFactory
                                .WithLogging(new XUnitLoggerFactory(this.output))
                                .WithApiResource(new ApiResource(apiResourceName, apiResourceDisplayName))
                                .WithClient(new Client
            {
                ClientId = clientId,
                ClientSecrets = new List <Secret> {
                    new Secret(clientSecret.Sha256())
                },
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                AllowedScopes = new List <string> {
                    apiResourceName
                },
            }).Create())
            {
                using (var client = clientFactory
                                    .WithClientId(clientId)
                                    .WithClientSecret(clientSecret)
                                    .Create(server))
                {
                    using (var tokenClient = await client.CreateTokenClient())
                    {
                        var response = await tokenClient.RequestClientCredentialsAsync();

                        Assert.NotNull(response.AccessToken);
                    }
                }
            }
        }