Example #1
0
        public static OAuthTicket AuthorizeWithCredentials(OAuthTicket ticket, string username, string password, string baseUrl, string authorizeUrl)
        {
            var restClient = new RestSharp.RestClient(baseUrl);
            restClient.Authenticator = OAuth1Authenticator.ForClientAuthentication(ticket.ConsumerKey, ticket.ConsumerSecret, username, password);

            var request = new RestRequest(authorizeUrl, Method.POST);
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(username + " " + password);

            request.AddHeader("Content-Type", "application/xml");
            request.AddParameter("ec", System.Convert.ToBase64String(toEncodeAsBytes, 0, toEncodeAsBytes.Length));
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK) {
                throw new ApiAccessException(response.StatusDescription) {
                    StatusCode = response.StatusCode,
                    StatusDescription = response.StatusDescription,
                    RequestUrl = response.ResponseUri.AbsoluteUri
                };
            }
            else {
                var qs = HttpUtility.ParseQueryString(response.Content);
                ticket.AccessToken = qs["oauth_token"];
                ticket.AccessTokenSecret = qs["oauth_token_secret"];
                return ticket;
            }
        }
Example #2
0
        public virtual IRestResponse AuthorizeFirstParty(OAuthTicket ticket, string username, string password, string authorizeUrl)
        {
            var restClient = new RestSharp.RestClient(this.BaseUrl);

            restClient.Authenticator = OAuth1Authenticator.ForClientAuthentication(ticket.ConsumerKey, ticket.ConsumerSecret, username, password);

            var request = new RestRequest(authorizeUrl, Method.POST);

            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(username + " " + password);

            request.AddHeader("Content-Type", "application/xml");
            request.AddParameter("ec", System.Convert.ToBase64String(toEncodeAsBytes, 0, toEncodeAsBytes.Length));
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ApiAccessException(response.StatusDescription)
                      {
                          StatusCode        = response.StatusCode,
                          StatusDescription = response.StatusDescription,
                          RequestUrl        = response.ResponseUri.AbsoluteUri
                      };
            }
            else
            {
                return(response);
            }
        }
Example #3
0
        public static OAuthTicket AuthorizeWithCredentials(OAuthTicket ticket, string username, string password, string baseUrl, string authorizeUrl)
        {
            var restClient = new RestSharp.RestClient(baseUrl);

            restClient.Authenticator = OAuth1Authenticator.ForClientAuthentication(ticket.ConsumerKey, ticket.ConsumerSecret, username, password);

            var request = new RestRequest(authorizeUrl, Method.POST);

            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(username + " " + password);

            request.AddHeader("Content-Type", "application/xml");
            request.AddParameter("ec", System.Convert.ToBase64String(toEncodeAsBytes, 0, toEncodeAsBytes.Length));
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ApiAccessException(response.StatusDescription)
                      {
                          StatusCode        = response.StatusCode,
                          StatusDescription = response.StatusDescription,
                          RequestUrl        = response.ResponseUri.AbsoluteUri
                      };
            }
            else
            {
                var qs = HttpUtility.ParseQueryString(response.Content);
                ticket.AccessToken       = qs["oauth_token"];
                ticket.AccessTokenSecret = qs["oauth_token_secret"];
                return(ticket);
            }
        }
Example #4
0
        public static OAuthTicket GetRequestToken(OAuthTicket ticket, string callback, string requestTokenUrl, string baseUrl)
        {
            var restClient = new RestSharp.RestClient(baseUrl);

            restClient.Authenticator = OAuth1Authenticator.ForRequestToken(ticket.ConsumerKey, ticket.ConsumerSecret, callback);

            var request  = new RestRequest(requestTokenUrl, Method.POST);
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ApiAccessException(response.StatusDescription)
                      {
                          StatusCode        = response.StatusCode,
                          StatusDescription = response.StatusDescription,
                          RequestUrl        = response.ResponseUri.AbsoluteUri
                      };
            }
            else
            {
                var qs = HttpUtility.ParseQueryString(response.Content);
                ticket.AccessToken       = qs["oauth_token"];
                ticket.AccessTokenSecret = qs["oauth_token_secret"];
                return(ticket);
            }
        }
Example #5
0
        public static OAuthTicket GetRequestToken(OAuthTicket ticket, string callback, string requestTokenUrl)
        {
            var restClient = new RestSharp.RestClient();
            restClient.Authenticator = OAuth1Authenticator.ForRequestToken(ticket.ConsumerKey, ticket.ConsumerSecret, callback);

            var request = new RestRequest(requestTokenUrl, Method.POST);
            var response = restClient.Execute(request);

            return null;
        }
Example #6
0
        public static IRestResponse ExchangeRequestToken(OAuthTicket ticket, string baseurl, string accessTokenUrl, string additionalParamters = null)
        {
            var restClient = new RestSharp.RestClient(baseurl);

            restClient.Authenticator = OAuth1Authenticator.ForAccessToken(ticket.ConsumerKey, ticket.ConsumerSecret, ticket.AccessToken, ticket.AccessTokenSecret);
            var request = new RestRequest(accessTokenUrl, Method.POST);

            string[] additionParms = additionalParamters.Split('&');

            foreach (var current in additionParms)
            {
                string[] nameValue = current.Split('=');

                if (nameValue.Length == 2)
                {
                    request.AddParameter(nameValue[0], nameValue[1]);
                }
            }

            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ApiAccessException(response.StatusDescription)
                      {
                          StatusCode        = response.StatusCode,
                          StatusDescription = response.StatusDescription,
                          RequestUrl        = response.ResponseUri.AbsoluteUri
                      };
            }
            else
            {
                var qs = RestSharp.Extensions.MonoHttp.HttpUtility.ParseQueryString(response.Content);
                ticket.AccessToken       = qs["oauth_token"];
                ticket.AccessTokenSecret = qs["oauth_token_secret"];

                return(response);
            }
        }
Example #7
0
        public static IRestResponse ExchangeRequestToken(OAuthTicket ticket, string baseurl, string accessTokenUrl)
        {
            var restClient = new RestSharp.RestClient(baseurl);

            restClient.Authenticator = OAuth1Authenticator.ForAccessToken(ticket.ConsumerKey, ticket.ConsumerSecret, ticket.AccessToken, ticket.AccessTokenSecret);

            var request  = new RestRequest(accessTokenUrl, Method.POST);
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ApiAccessException(response.StatusDescription)
                      {
                          StatusCode        = response.StatusCode,
                          StatusDescription = response.StatusDescription,
                          RequestUrl        = response.ResponseUri.AbsoluteUri
                      };
            }
            else
            {
                return(response);
            }
        }
Example #8
0
 protected ApiSet(OAuthTicket ticket, string baseUrl, ContentType contentType)
 {
     _ticket      = ticket;
     _baseUrl     = baseUrl;
     _contentType = contentType;
 }
Example #9
0
        public static IRestResponse ExchangeRequestToken(OAuthTicket ticket, string baseurl, string accessTokenUrl)
        {
            var restClient = new RestSharp.RestClient(baseurl);
            restClient.Authenticator = OAuth1Authenticator.ForAccessToken(ticket.ConsumerKey, ticket.ConsumerSecret, ticket.AccessToken, ticket.AccessTokenSecret);

            var request = new RestRequest(accessTokenUrl, Method.POST);
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK) {
                throw new ApiAccessException(response.StatusDescription) {
                    StatusCode = response.StatusCode,
                    StatusDescription = response.StatusDescription,
                    RequestUrl = response.ResponseUri.AbsoluteUri
                };
            }
            else {
                return response;
            }
        }
Example #10
0
 public Client(OAuthTicket ticket, string baseUrl)
 {
     this.Ticket = ticket;
     this.BaseUrl = baseUrl;
 }
Example #11
0
 public Client(OAuthTicket ticket)
 {
 }
Example #12
0
        public virtual IRestResponse AuthorizeFirstParty(OAuthTicket ticket, string username, string password, string authorizeUrl)
        {
            var restClient = new RestSharp.RestClient(this.BaseUrl);
            restClient.Authenticator = OAuth1Authenticator.ForClientAuthentication(ticket.ConsumerKey, ticket.ConsumerSecret, username, password);

            var request = new RestRequest(authorizeUrl, Method.POST);
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(username + " " + password);

            request.AddHeader("Content-Type", "application/xml");
            request.AddParameter("ec", System.Convert.ToBase64String(toEncodeAsBytes, 0, toEncodeAsBytes.Length));
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK) {
                throw new ApiAccessException(response.StatusDescription) {
                    StatusCode = response.StatusCode,
                    StatusDescription = response.StatusDescription,
                    RequestUrl = response.ResponseUri.AbsoluteUri
                };
            }
            else {
                return response;
            }
        }
Example #13
0
        public static OAuthTicket GetRequestToken(OAuthTicket ticket, string callback, string requestTokenUrl, string baseUrl)
        {
            var restClient = new RestSharp.RestClient(baseUrl);
            restClient.Authenticator = OAuth1Authenticator.ForRequestToken(ticket.ConsumerKey, ticket.ConsumerSecret, callback);

            var request = new RestRequest(requestTokenUrl, Method.POST);
            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK) {
                throw new ApiAccessException(response.StatusDescription) {
                    StatusCode = response.StatusCode,
                    StatusDescription = response.StatusDescription,
                    RequestUrl = response.ResponseUri.AbsoluteUri
                };
            }
            else {
                var qs = HttpUtility.ParseQueryString(response.Content);
                ticket.AccessToken = qs["oauth_token"];
                ticket.AccessTokenSecret = qs["oauth_token_secret"];
                return ticket;
            }
        }
Example #14
0
        public static IRestResponse ExchangeRequestToken(OAuthTicket ticket, string baseurl, string accessTokenUrl, string additionalParamters = null)
        {
            var restClient = new RestSharp.RestClient(baseurl);
            restClient.Authenticator = OAuth1Authenticator.ForAccessToken(ticket.ConsumerKey, ticket.ConsumerSecret, ticket.AccessToken, ticket.AccessTokenSecret);
            var request = new RestRequest(accessTokenUrl, Method.POST);

            string[] additionParms = additionalParamters.Split('&');

            foreach (var current in additionParms) {
                string[] nameValue = current.Split('=');

                if (nameValue.Length == 2) {
                    request.AddParameter(nameValue[0], nameValue[1]);
                }
            }

            var response = restClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK) {
                throw new ApiAccessException(response.StatusDescription) {
                    StatusCode = response.StatusCode,
                    StatusDescription = response.StatusDescription,
                    RequestUrl = response.ResponseUri.AbsoluteUri
                };
            }
            else {
                var qs = RestSharp.Extensions.MonoHttp.HttpUtility.ParseQueryString(response.Content);
                ticket.AccessToken = qs["oauth_token"];
                ticket.AccessTokenSecret = qs["oauth_token_secret"];

                return response;
            }
        }
Example #15
0
 public Client(OAuthTicket ticket, string baseUrl)
 {
     this.Ticket  = ticket;
     this.BaseUrl = baseUrl;
 }
Example #16
0
 public Client(OAuthTicket ticket)
 {
 }