/// <summary>
        /// Creates a client token.
        /// </summary>
        /// <param name="lifetime">The lifetime.</param>
        /// <param name="clientId">The client identifier.</param>
        /// <param name="scopes">The scopes.</param>
        /// <param name="audiences">The audiences.</param>
        /// <returns>The client token.</returns>
        public async Task <TokenResult> CreateClientToken(
            int lifetime,
            string clientId,
            IEnumerable <string> scopes,
            IEnumerable <string> audiences)
        {
            var json = JsonConvert.SerializeObject(new IdentityServerClientTokenRequest
            {
                Lifetime  = lifetime,
                ClientId  = clientId,
                Scopes    = scopes,
                Audiences = audiences,
            });

            var content = new StringContent(json, Encoding.UTF8, "application/json");

            using (var client = this.testServer.CreateClient())
            {
                var response = await client.PostAsync("api/test/token/create-client", content);

                var responseBody = await response.Content.ReadAsStringAsync();

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(TokenResult.Failure(response.StatusCode, responseBody));
                }

                var token = JsonConvert.DeserializeObject <IdentityServerTokenResponse>(responseBody);
                return(TokenResult.Success(token.Token));
            }
        }
        /// <summary>
        /// Creates a token.
        /// </summary>
        /// <param name="lifetime">The lifetime.</param>
        /// <param name="claims">The claims.</param>
        /// <returns>The token.</returns>
        public async Task <TokenResult> CreateToken(int lifetime, List <Claim> claims)
        {
            var json = JsonConvert.SerializeObject(new IdentityServerTokenRequest
            {
                Lifetime = lifetime,
                Claims   = claims.Select(c => new SerializableClaim(
                                             type: c.Type,
                                             value: c.Value,
                                             valueType: c.ValueType,
                                             issuer: c.Issuer,
                                             originalIssuer: c.OriginalIssuer)).ToList(),
            });

            var content = new StringContent(json, Encoding.UTF8, "application/json");

            using (var client = this.testServer.CreateClient())
            {
                var response = await client.PostAsync("api/test/token/create", content);

                var responseBody = await response.Content.ReadAsStringAsync();

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(TokenResult.Failure(response.StatusCode, responseBody));
                }

                var token = JsonConvert.DeserializeObject <IdentityServerTokenResponse>(responseBody);
                return(TokenResult.Success(token.Token));
            }
        }