Beispiel #1
0
        /// <summary>
        /// Adds a "Bearer" Token Authorization Header to the request.
        /// Used when authorization against a resource that uses OAUTH2
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="token">Token to apply to the header</param>
        /// <returns>The same <see cref="HttpSettings"/> instance so that multiple calls can be chained.</returns>
        public static HttpSettings UseBearerAuthorization(this HttpSettings settings, string token)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            return(settings.SetAuthorization("Bearer", token));
        }
Beispiel #2
0
        /// <summary>
        /// Adds a "Basic" Authorization Header to the request.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="userName">The userName used to authorize to the resource.</param>
        /// <param name="password">The credentials containing the authentication information of the user agent for</param>
        /// <returns>The same <see cref="HttpSettings"/> instance so that multiple calls can be chained.</returns>
        public static HttpSettings UseBasicAuthorization(this HttpSettings settings, string userName, string password)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException(nameof(userName));
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(userName + ":" + password));

            settings.SetAuthorization("Basic", credentials);
            return(settings);
        }