public void Initialize(ConfigurableHttpClient httpClient)
        {
            var backOff = CreateBackOff();

            // Add exception handler and \ or unsuccessful response handler.
            if ((Policy & ExponentialBackOffPolicy.Exception) == ExponentialBackOffPolicy.Exception)
            {
                httpClient.MessageHandler.ExceptionHandlers.Add(backOff);
            }

            if ((Policy & ExponentialBackOffPolicy.UnsuccessfulResponse503) ==
                ExponentialBackOffPolicy.UnsuccessfulResponse503)
            {
                httpClient.MessageHandler.UnsuccessfulResponseHandlers.Add(backOff);
            }
        }
        public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args)
        {
            // Create the handler.
            var handler = CreateHandler(args);
            var configurableHandler = new ConfigurableMessageHandler(handler)
                {
                    ApplicationName = args.ApplicationName
                };

            // Create the client.
            var client = new ConfigurableHttpClient(configurableHandler);
            foreach (var initializer in args.Initializers)
            {
                initializer.Initialize(client);
            }

            return client;
        }
 public void Initialize(ConfigurableHttpClient httpClient)
 {
     httpClient.MessageHandler.ExecuteInterceptors.Add(this);
     httpClient.MessageHandler.UnsuccessfulResponseHandlers.Add(this);
 }
        /// <summary>Constructs a new service account credential using the given initializer.</summary>
        public ServiceCredential(Initializer initializer)
        {
            tokenServerUrl = initializer.TokenServerUrl;
            accessMethod = initializer.AccessMethod.ThrowIfNull("initializer.AccessMethod");
            clock = initializer.Clock.ThrowIfNull("initializer.Clock");

            // Set the HTTP client.
            var httpArgs = new CreateHttpClientArgs();

            // Add exponential back-off initializer if necessary.
            if (initializer.DefaultExponentialBackOffPolicy != ExponentialBackOffPolicy.None)
            {
                httpArgs.Initializers.Add(
                    new ExponentialBackOffInitializer(initializer.DefaultExponentialBackOffPolicy,
                        () => new BackOffHandler(new ExponentialBackOff())));
            }
            httpClient = (initializer.HttpClientFactory ?? new HttpClientFactory()).CreateHttpClient(httpArgs);
        }
        /// <summary>Constructs a new flow using the initializer's properties.</summary>
        public AuthorizationCodeFlow(Initializer initializer)
        {
            clientSecrets = initializer.ClientSecrets;
            if (clientSecrets == null)
            {
                if (initializer.ClientSecretsStream == null)
                {
                    throw new ArgumentException("You MUST set ClientSecret or ClientSecretStream on the initializer");
                }

                using (initializer.ClientSecretsStream)
                {
                    clientSecrets = GoogleClientSecrets.Load(initializer.ClientSecretsStream).Secrets;
                }
            }
            else if (initializer.ClientSecretsStream != null)
            {
                throw new ArgumentException(
                    "You CAN'T set both ClientSecrets AND ClientSecretStream on the initializer");
            }

            accessMethod = initializer.AccessMethod.ThrowIfNull("Initializer.AccessMethod");
            clock = initializer.Clock.ThrowIfNull("Initializer.Clock");
            tokenServerUrl = initializer.TokenServerUrl.ThrowIfNullOrEmpty("Initializer.TokenServerUrl");
            authorizationServerUrl = initializer.AuthorizationServerUrl.ThrowIfNullOrEmpty
                ("Initializer.AuthorizationServerUrl");

            dataStore = initializer.DataStore;
            if (dataStore == null)
            {
                Logger.Warning("Datastore is null, as a result the user's credential will not be stored");
            }
            scopes = initializer.Scopes;

            // Set the HTTP client.
            var httpArgs = new CreateHttpClientArgs();

            // Add exponential back-off initializer if necessary.
            if (initializer.DefaultExponentialBackOffPolicy != ExponentialBackOffPolicy.None)
            {
                httpArgs.Initializers.Add(
                    new ExponentialBackOffInitializer(initializer.DefaultExponentialBackOffPolicy,
                        () => new BackOffHandler(new ExponentialBackOff())));
            }
            httpClient = (initializer.HttpClientFactory ?? new HttpClientFactory()).CreateHttpClient(httpArgs);
        }
 void IConfigurableHttpClientInitializer.Initialize(ConfigurableHttpClient httpClient)
 {
     credential.Initialize(httpClient);
 }
 protected override void Initialize(ConfigurableHttpClient httpClient)
 {
     credential.Initialize(httpClient);
 }
        // We're explicitly implementing all the interfaces to only expose the members user actually
        // needs to see. Because you cannot make explicit interface implementors abstract, they are redirecting
        // to the following protected abstract members.

        /// <summary>Initializes a HTTP client.</summary>
        protected abstract void Initialize(ConfigurableHttpClient httpClient);