NuxeoClient.Authorization.GenerateAuthorizationParameter C# (CSharp) Method

GenerateAuthorizationParameter() public method

Generates a string with the contents for the HTTP authorization header.
public GenerateAuthorizationParameter ( ) : string
return string
        public string GenerateAuthorizationParameter()
        {
            switch (Method)
            {
                case Methods.Basic:
                    string unencodedUsernameAndPassword = string.Format("{0}:{1}", Username, Password);
                    byte[] unencodedBytes = UTF8Encoding.UTF8.GetBytes(unencodedUsernameAndPassword);
                    string base64UsernameAndPassword = Convert.ToBase64String(unencodedBytes);
                    return string.Format("Basic {0}", base64UsernameAndPassword);
                /*case Methods.Portal:
                    return string.Empty;

                case Methods.Proxy:
                    return string.Empty;*/
                default:
                    return string.Empty;
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Sets the authorization information to be sent in all requests.
        /// </summary>
        /// <param name="auth">The authorization data.</param>
        /// <returns>The current <see cref="Client"/> instace.</returns>
        public Client SetAuthorization(Authorization auth)
        {
            Authorization = auth ?? new Authorization();
            string authorizationHeaderValue = Authorization.GenerateAuthorizationParameter();

            if (http.DefaultRequestHeaders.Contains("Authorization"))
            {
                http.DefaultRequestHeaders.Remove("Authorization");
            }
            http.DefaultRequestHeaders.Add("Authorization", authorizationHeaderValue);
            return(this);
        }