Exemplo n.º 1
0
        public async System.Threading.Tasks.Task <CopyClient> GetAccessTokenAsync(string verifier)
        {
            string authzHeader = Helpers.AuthorizationHeader.CreateForAccess(Config.ConsumerKey, Config.ConsumerSecret, Token, TokenSecret, verifier);

            string url = string.Format(Helper.URL.AccessToken);

            Models.HttpRequestItem httpRequestItem = new Models.HttpRequestItem()
            {
                URL           = Helper.URL.AccessToken,
                HttpMethod    = System.Net.Http.HttpMethod.Get,
                AuthzHeader   = authzHeader,
                HttpContent   = null,
                IsDataRequest = false
            };

            HttpRequest.HttpRequestHandler httpRequestHandler = new HttpRequest.HttpRequestHandler();
            string executeAsync = await httpRequestHandler.ReadAsStringAsync(httpRequestItem);

            string[] kvpairs = executeAsync.Split('&');
            System.Collections.Generic.Dictionary <string, string> parameters = System.Linq.Enumerable.ToDictionary(System.Linq.Enumerable.Select(kvpairs, pair => pair.Split('=')), kv => kv[0], kv => kv[1]);

            if (parameters.ContainsKey("oauth_error_message"))
            {
                return(null);
            }
            else
            {
                return(new CopyClient(Config, new Models.OAuthToken()
                {
                    Token = parameters["oauth_token"],
                    TokenSecret = parameters["oauth_token_secret"]
                }));
            }
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task <Models.OAuthToken> GetRequestTokenAsync()
        {
            string url;

            if (Scope != null)
            {
                string serializedScope = Newtonsoft.Json.JsonConvert.SerializeObject(Scope);

                url = string.Format("{0}?scope={1}", Helper.URL.RequestToken, System.Net.WebUtility.UrlEncode(serializedScope));
            }
            else
            {
                url = Helper.URL.RequestToken;
            }

            string authzHeader = Helpers.AuthorizationHeader.CreateForRequest(CallbackURL, Config.ConsumerKey, Config.ConsumerSecret, url);

            Models.HttpRequestItem httpRequestItem = new Models.HttpRequestItem()
            {
                URL           = url,
                HttpMethod    = System.Net.Http.HttpMethod.Get,
                AuthzHeader   = authzHeader,
                HttpContent   = null,
                IsDataRequest = false
            };

            HttpRequest.HttpRequestHandler httpRequestHandler = new HttpRequest.HttpRequestHandler();
            string executeAsync = await httpRequestHandler.ReadAsStringAsync(httpRequestItem);

            if (!string.IsNullOrEmpty(executeAsync))
            {
                string[] kvpairs = executeAsync.Split('&');
                System.Collections.Generic.Dictionary <string, string> parameters = System.Linq.Enumerable.ToDictionary(System.Linq.Enumerable.Select(kvpairs, pair => pair.Split('=')), kv => kv[0], kv => kv[1]);


                Token       = parameters["oauth_token"];
                TokenSecret = parameters["oauth_token_secret"];
                AuthCodeUri = new System.Uri(string.Format("{0}?oauth_token={1}", Helper.URL.Authorize, Token));

                return(new Models.OAuthToken()
                {
                    Token = Token,
                    TokenSecret = TokenSecret
                });
            }

            return(new Models.OAuthToken());
        }
Exemplo n.º 3
0
        public async System.Threading.Tasks.Task<Models.OAuthToken> GetRequestTokenAsync()
        {
            string url;
            if (Scope != null)
            {
                string serializedScope = Newtonsoft.Json.JsonConvert.SerializeObject(Scope);

                url = string.Format("{0}?scope={1}", Helper.URL.RequestToken, System.Net.WebUtility.UrlEncode(serializedScope));
            }
            else
            {
                url = Helper.URL.RequestToken;
            }

            string authzHeader = Helpers.AuthorizationHeader.CreateForRequest(CallbackURL, Config.ConsumerKey, Config.ConsumerSecret, url);

            Models.HttpRequestItem httpRequestItem = new Models.HttpRequestItem()
            {
                URL = url,
                HttpMethod = System.Net.Http.HttpMethod.Get,
                AuthzHeader = authzHeader,
                HttpContent = null,
                IsDataRequest = false
            };

            HttpRequest.HttpRequestHandler httpRequestHandler = new HttpRequest.HttpRequestHandler();
            string executeAsync = await httpRequestHandler.ReadAsStringAsync(httpRequestItem);

            if (!string.IsNullOrEmpty(executeAsync))
            {
                string[] kvpairs = executeAsync.Split('&');
                System.Collections.Generic.Dictionary<string, string> parameters = System.Linq.Enumerable.ToDictionary(System.Linq.Enumerable.Select(kvpairs, pair => pair.Split('=')), kv => kv[0], kv => kv[1]);


                Token = parameters["oauth_token"];
                TokenSecret = parameters["oauth_token_secret"];
                AuthCodeUri = new System.Uri(string.Format("{0}?oauth_token={1}", Helper.URL.Authorize, Token));

                return new Models.OAuthToken()
                {
                    Token = Token,
                    TokenSecret = TokenSecret
                };
            }

            return new Models.OAuthToken();
        }
Exemplo n.º 4
0
        public async System.Threading.Tasks.Task<CopyClient> GetAccessTokenAsync(string verifier)
        {
            string authzHeader = Helpers.AuthorizationHeader.CreateForAccess(Config.ConsumerKey, Config.ConsumerSecret, Token, TokenSecret, verifier);

            string url = string.Format(Helper.URL.AccessToken);

            Models.HttpRequestItem httpRequestItem = new Models.HttpRequestItem()
            {
                URL = Helper.URL.AccessToken,
                HttpMethod = System.Net.Http.HttpMethod.Get,
                AuthzHeader = authzHeader,
                HttpContent = null,
                IsDataRequest = false
            };

            HttpRequest.HttpRequestHandler httpRequestHandler = new HttpRequest.HttpRequestHandler();
            string executeAsync = await httpRequestHandler.ReadAsStringAsync(httpRequestItem);

            string[] kvpairs = executeAsync.Split('&');
            System.Collections.Generic.Dictionary<string, string> parameters = System.Linq.Enumerable.ToDictionary(System.Linq.Enumerable.Select(kvpairs, pair => pair.Split('=')), kv => kv[0], kv => kv[1]);

            if (parameters.ContainsKey("oauth_error_message"))
            {
                return null;
            }
            else
            {
                return new CopyClient(Config, new Models.OAuthToken()
                {
                    Token = parameters["oauth_token"],
                    TokenSecret = parameters["oauth_token_secret"]
                });
            }
        }