コード例 #1
0
        /// <summary>
        /// Sets up a bearer token authorisation header.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="bearerToken">Token to be appended to the header value.</param>
        /// <returns></returns>
        public static RestConfiguration WithBearerAuthorization(this RestConfiguration config, string bearerToken)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (bearerToken == null)
            {
                throw new ArgumentNullException(nameof(bearerToken));
            }

            config.WithAuthorization($"Bearer {bearerToken}");

            return(config);
        }
コード例 #2
0
        /// <summary>
        /// Sets up a bearer token authorisation header.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="username">Username to generate the basic header authorization</param>
        /// <param name="password">Password to generate the basic header authorization</param>
        /// <returns></returns>
        public static RestConfiguration WithBasicAuthorization(this RestConfiguration config, string username, string password)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }


            config.WithAuthorization($"Basic {HeaderHelper.BasicAuthorizationHeaderValue(username, password)}");

            return(config);
        }