示例#1
0
        private OAuthResponse GetResource(NameValueCollection parameters, string contentType, System.IO.Stream bodyStream)
        {
            OAuthResponse response;

            HttpWebRequest request = this.PrepareProtectedResourceRequest(parameters, contentType, bodyStream);

            // A null value for the HttpWebRequest is returned when a ResponseToken is returned
            // and no one has returned in the AuthorizationHandler continue with getting an AccessToken
            // or an RequestToken exists but the AccessToken request was refused.
            if (request == null)
            {
                response = new OAuthResponse(this.RequestToken);
            }
            else
            {
                OAuthResource   resource;
                OAuthParameters responseParameters;

                try
                {
                    resource = new OAuthResource((HttpWebResponse)request.GetResponse());

                    // Parse the parameters and re-throw any OAuthRequestException from the service provider
                    responseParameters = OAuthParameters.Parse(resource);
                    OAuthRequestException.TryRethrow(responseParameters);

                    // If nothing is thrown then we should have a valid resource.
                    response = new OAuthResponse(this.AccessToken ?? this.RequestToken, resource);
                }
                catch (WebException e)
                {
                    // Parse the parameters and re-throw any OAuthRequestException from the service provider
                    responseParameters = OAuthParameters.Parse(e.Response as HttpWebResponse);
                    OAuthRequestException.TryRethrow(responseParameters);

                    // If no OAuthRequestException, rethrow the WebException
                    #warning TODO: We have consumer the WebException's body so rethrowing it is pretty pointless; wrap the WebException in an OAuthProtocolException and store the body (create an OAuthResource before parsing parameters)
                    throw;
                }
            }

            return(response);
        }
示例#2
0
        private OAuthResponse GetResource(NameValueCollection parameters, string contentType, System.IO.Stream bodyStream)
        {
            OAuthResponse response;

            HttpWebRequest request = this.PrepareProtectedResourceRequest(parameters, contentType, bodyStream);

            // A null value for the HttpWebRequest is returned when a ResponseToken is returned
            // and no one has returned in the AuthorizationHandler continue with getting an AccessToken
            // or an RequestToken exists but the AccessToken request was refused.
            if (request == null)
                response = new OAuthResponse(this.RequestToken);
            else
            {
                OAuthResource resource;
                OAuthParameters responseParameters;

                try
                {
                    resource = new OAuthResource((HttpWebResponse)request.GetResponse());

                    // Parse the parameters and re-throw any OAuthRequestException from the service provider
                    responseParameters = OAuthParameters.Parse(resource);
                    OAuthRequestException.TryRethrow(responseParameters);

                    // If nothing is thrown then we should have a valid resource.
                    response = new OAuthResponse(this.AccessToken ?? this.RequestToken, resource);
                }
                catch (WebException e)
                {
                    // Parse the parameters and re-throw any OAuthRequestException from the service provider
                    responseParameters = OAuthParameters.Parse(e.Response as HttpWebResponse);
                    OAuthRequestException.TryRethrow(responseParameters);

                    // If no OAuthRequestException, rethrow the WebException
                    #warning TODO: We have consumer the WebException's body so rethrowing it is pretty pointless; wrap the WebException in an OAuthProtocolException and store the body (create an OAuthResource before parsing parameters)
                    throw;
                }
            }

            return response;
        }