Exemple #1
0
            /// <summary>
            /// Generates an authorization URL based on the current state of the
            /// builder.
            /// </summary>
            /// <returns>
            /// An authorization URL based on the current state of the builder.
            /// </returns>
            public string Build()
            {
                var authUrl = this.enterpriseConnect ? this.urlProvider.EnterpriseConnectAuthorizationUrl : this.urlProvider.AuthorizationUrl;

                var urlBuilder = new UrlBuilder()
                                 .Url(authUrl)
                                 .AddParameter("client_id", this.clientId)
                                 .AddParameter("response_type", "code")
                                 .AddParameter("redirect_uri", this.redirectUri);

                if (this.enterpriseConnect)
                {
                    urlBuilder.AddParameter("delegated_scope", string.Join(" ", this.scope));
                    urlBuilder.AddParameter("scope", string.Join(" ", this.enterpriseConnectScope));
                }
                else
                {
                    urlBuilder.AddParameter("scope", string.Join(" ", this.scope));
                }

                if (this.state != null)
                {
                    urlBuilder.AddParameter("state", this.state);
                }

                if (this.avoidLinking.HasValue)
                {
                    urlBuilder.AddParameter("avoid_linking", this.avoidLinking.Value);
                }

                if (this.linkToken != null)
                {
                    urlBuilder.AddParameter("link_token", this.linkToken);
                }

                if (this.providerName != null)
                {
                    urlBuilder.AddParameter("provider_name", this.providerName);
                }

                return(urlBuilder.Build());
            }
            /// <summary>
            /// Generates an authorization URL based on the current state of the
            /// builder.
            /// </summary>
            /// <returns>
            /// An authorization URL based on the current state of the builder.
            /// </returns>
            public string Build()
            {
                var urlBuilder = new UrlBuilder()
                                 .Url(AuthorizationUrl)
                                 .AddParameter("client_id", this.clientId)
                                 .AddParameter("response_type", "code")
                                 .AddParameter("scope", string.Join(" ", this.scope))
                                 .AddParameter("redirect_uri", this.redirectUri);

                if (this.state != null)
                {
                    urlBuilder.AddParameter("state", this.state);
                }

                if (this.avoidLinking.HasValue)
                {
                    urlBuilder.AddParameter("avoid_linking", this.avoidLinking.Value);
                }

                return(urlBuilder.Build());
            }
Exemple #3
0
        /// <inheritdoc/>
        public HttpResponse GetResponse(HttpRequest request)
        {
            Preconditions.NotNull("request", request);

            var urlBuilder = new UrlBuilder().Url(request.Url);

            if (request.QueryString != null)
            {
                foreach (var item in request.QueryString)
                {
                    urlBuilder.AddParameter(item.Key, item.Value);
                }
            }

            var url = urlBuilder.Build();

            var httpRequest = (HttpWebRequest)WebRequest.Create(url);

            httpRequest.KeepAlive = true;
            httpRequest.Method    = request.Method;
            httpRequest.UserAgent = UserAgentString;

            MapHeaders(request, httpRequest);

            httpRequest.AutomaticDecompression      = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            httpRequest.Headers["Content-Encoding"] = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3";

            try
            {
                WriteRequestBody(request, httpRequest);
                return(GetResponse(httpRequest));
            }
            catch (Exception ex)
            {
                var message = string.Format(
                    "Failed to get a response to the request - {0}",
                    ex.Message);
                throw new CronofyException(message, ex);
            }
        }
        /// <inheritdoc/>
        public HttpResponse GetResponse(HttpRequest request)
        {
            Preconditions.NotNull("request", request);

            var urlBuilder = new UrlBuilder().Url(request.Url);

            if (request.QueryString != null)
            {
                foreach (var item in request.QueryString)
                {
                    urlBuilder.AddParameter(item.Key, item.Value);
                }
            }

            var url = urlBuilder.Build();

            var httpRequest = (HttpWebRequest)WebRequest.Create(url);

            httpRequest.KeepAlive = true;
            httpRequest.Method = request.Method;
            httpRequest.UserAgent = UserAgentString;

            MapHeaders(request, httpRequest);

            try
            {
                WriteRequestBody(request, httpRequest);
                return GetResponse(httpRequest);
            }
            catch (Exception ex)
            {
                var message = string.Format(
                    "Failed to get a response to the request - {0}",
                    ex.Message);
                throw new CronofyException(message, ex);
            }
        }
            /// <summary>
            /// Generates an authorization URL based on the current state of the
            /// builder.
            /// </summary>
            /// <returns>
            /// An authorization URL based on the current state of the builder.
            /// </returns>
            public string Build()
            {
                var authUrl = this.enterpriseConnect ? EnterpriseConnectAuthorizationUrl : AuthorizationUrl;

                var urlBuilder = new UrlBuilder()
                    .Url(authUrl)
                    .AddParameter("client_id", this.clientId)
                    .AddParameter("response_type", "code")
                    .AddParameter("redirect_uri", this.redirectUri);

                if (this.enterpriseConnect)
                {
                    urlBuilder.AddParameter("delegated_scope", string.Join(" ", this.scope));
                    urlBuilder.AddParameter("scope", string.Join(" ", this.enterpriseConnectScope));
                }
                else
                {
                    urlBuilder.AddParameter("scope", string.Join(" ", this.scope));
                }

                if (this.state != null)
                {
                    urlBuilder.AddParameter("state", this.state);
                }

                if (this.avoidLinking.HasValue)
                {
                    urlBuilder.AddParameter("avoid_linking", this.avoidLinking.Value);
                }

                return urlBuilder.Build();
            }