Adds cookie authentication support to http requests. It does this by adding the cookie header for CouchDB using request interceptor pipeline in IBM.Cloudant.Client.HttpHelper. If a response has a response code of 401, it will fetch a cookie from the server using provided credentials and tell IBM.Cloudant.Client.HttpHelper to reply the request by setting IBM.Cloudant.Client.HttpConnectionInterceptorContext.replayRequest property to true. If the request to get the cookie for use in future request fails with a 401 status code (or any status that indicates client error) cookie authentication will not be attempted again.
This class is used for adding cookie authentication to HTTP requests.
Inheritance: IHttpConnectionRequestInterceptor, IHttpConnectionResponseInterceptor
コード例 #1
0
        /// <summary>
        /// Constructs a new instance of this class and connects to the cloudant server using a builder class.
        /// </summary>
        /// <param name="builder">Builder class. <see cref="IBM.Cloudant.Client.CloudantClientBuilder"/> </param>
        public CloudantClient(CloudantClientBuilder builder)
        {
            this.accountUri = builder.accountUri;
            this.username = builder.username;
            this.password = builder.password;

            List<IHttpConnectionInterceptor> interceptors = new List<IHttpConnectionInterceptor>();
            if (builder.interceptors != null)
            {
                interceptors.AddRange(builder.interceptors);
            }

            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                var cookieInterceptor = new CookieInterceptor(username, password);
                interceptors.Add(cookieInterceptor);
            }

            InitHttpHelper(interceptors);
        }
コード例 #2
0
        /// <summary>
        /// Constructs a new instance of this class and connects to the cloudant server using a builder class.
        /// </summary>
        /// <param name="builder">Builder class. <see cref="IBM.Cloudant.Client.CloudantClientBuilder"/> </param>
        public CloudantClient(CloudantClientBuilder builder)
        {
            this.accountUri = builder.accountUri;
            this.username   = builder.username;
            this.password   = builder.password;


            List <IHttpConnectionInterceptor> interceptors = new List <IHttpConnectionInterceptor>();

            if (builder.interceptors != null)
            {
                interceptors.AddRange(builder.interceptors);
            }

            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                var cookieInterceptor = new CookieInterceptor(username, password);
                interceptors.Add(cookieInterceptor);
            }

            InitHttpHelper(interceptors);
        }
コード例 #3
0
        public void testCookieInterceptor()
        {
            CookieInterceptor cookieInterceptor = new CookieInterceptor(TestConstants.username, TestConstants.password);

            client = new CloudantClientBuilder(TestConstants.account)
            {
                interceptors = new List<IHttpConnectionInterceptor>(){ cookieInterceptor }
            }.GetResult();

            db = client.Database(DBName);

            Assert.DoesNotThrow(async () =>
                {
                    await db.EnsureExistsAsync().ConfigureAwait(continueOnCapturedContext: false);
                },
                "Exception thrown while creating database using cookie interceptor. ");

            Assert.NotNull(db);
        }