예제 #1
0
        public WebRequest DelegatedRequest(string url, Format format)
        {
            var credentials = ((OAuthCredentials)Credentials);
            credentials.Version = "1.0";
            credentials.CallbackUrl = string.Empty;

            var request = new RestRequest
            {
                Credentials = Credentials,
                Path = "account/verify_credentials." + ((format == Format.Json) ? "json" : "xml"),
                Method = WebMethod.Get
            };

            // TODO: cannot intercept BuildEndpoint without having to mock RestClient
            var restClient = (RestClient)Client;
            var endpoint = request.BuildEndpoint(restClient);

            var webReq = (HttpWebRequest)WebRequest.Create(url);
            webReq.Headers = new WebHeaderCollection();
            webReq.Headers["X-Auth-Service-Provider"] = endpoint.ToString();

            var x = new OAuthWebQueryInfo();
            var query = Credentials.GetQueryFor(endpoint.ToString(), request, x, WebMethod.Get, true);
            var info = query.Info as OAuthWebQueryInfo;
            if (info != null)
            {
                var xVerifyCredentialsAuthorization = string.Format(AuthorizationTemplate, info.ConsumerKey, info.Token, info.SignatureMethod, info.Signature, info.Timestamp, info.Nonce, info.Version);
                webReq.Headers["X-Verify-Credentials-Authorization"] = xVerifyCredentialsAuthorization;
            }

            return webReq;
        }