Exemplo n.º 1
0
        public void SetAuthentication(Http.AuthenticationMethod authenticationMethod, string token)
        {
            string authentication = string.Empty;

            switch (authenticationMethod)
            {
            case Http.AuthenticationMethod.Basic:
                authentication = "Basic " + token;
                break;

            case Http.AuthenticationMethod.Bearer:
                authentication = "Bearer " + token;
                break;
            }

            if (!string.IsNullOrEmpty(authentication))
            {
                if (string.IsNullOrEmpty(Headers.AuthorizationHeader))
                {
                    Headers.Add("Authorization", authentication);
                }
                else
                {
                    Headers["Authorization"] = authentication;
                }
            }
        }
        public void SetAuthentication(Http.AuthenticationMethod authenticationMethod, string token)
        {
            // TODO: add support for more authntication types
            string authentication = null;

            switch (authenticationMethod)
            {
            case Http.AuthenticationMethod.Basic:
                authentication = "Basic " + token;
                break;

            case Http.AuthenticationMethod.Bearer:
                authentication = "Bearer " + token;
                break;
            }

            if (string.IsNullOrEmpty(Headers.AuthorizationHeader))
            {
                Headers.Add("Authorization", authentication);
            }
            else
            {
                Headers["Authorization"] = authentication;
            }
        }
Exemplo n.º 3
0
        public void SetAuthentication(Http.AuthenticationMethod authenticationMethod, string username, string password)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentException("Username is required", nameof(username));
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("Password is required", nameof(password));
            }

            string token = Base64Encode(username + ":" + password);

            SetAuthentication(authenticationMethod, token);
        }