Пример #1
0
        public void HandleHttpClientAuth(HttpClient client, HttpAuthType authType, string username, string password, string apiKey)
        {
            if (client == null)
            {
                //log
                throw new ArgumentException($"Authentication process handler failure. Invalid {typeof(HttpClient)} value");
            }
            if (!System.Enum.IsDefined(typeof(HttpAuthType), authType))
            {
                //log
                throw new ArgumentException($"Invalid {typeof(HttpAuthType)} value: {authType} in Authentication process handler");
            }

            switch (authType)
            {
            case HttpAuthType.NoAuth:
                return;

            case HttpAuthType.ApiKey:
                throw new NotImplementedException();

            case HttpAuthType.BearenToken:
                throw new NotImplementedException();

            case HttpAuthType.BasicAuth:
            {
                if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
                {
                    //log
                    throw new ArgumentException($"Invalid user input values for Basic Auth process");
                }

                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue(
                        "Basic", Convert.ToBase64String(
                            System.Text.ASCIIEncoding.ASCII.GetBytes(
                                $"{username}:{password}")));
            }
                return;

            case HttpAuthType.DigestAuth:
                throw new NotImplementedException();

            case HttpAuthType.AWSSignature:
                throw new NotImplementedException();

            case HttpAuthType.OAuth_v1:
                throw new NotImplementedException();

            case HttpAuthType.OAuth_v2:
                throw new NotImplementedException();
            }
        }
 public HttpTriggerConfig(HttpAuthType authType, HttpMethod[] methods)
 {
     this.AuthType = authType;
     this.Methods  = methods;
 }