Esempio n. 1
0
        private async Task GetTwitterUserNameAsync(string webAuthResultResponseData)
        {
            TwitterCredentials _appCredentials;
            //
            // Acquiring a access_token first
            //
            _appCredentials = new TwitterCredentials(_consumerKey, ConsumerSecret);
            _appCredentials.AccessToken = _accessToken;
            _appCredentials.AccessTokenSecret = _accessTokenSecret;
            var responseData = webAuthResultResponseData.Substring(webAuthResultResponseData.IndexOf("oauth_token"));
            string request_token = null;
            string oauth_verifier = null;
            var keyValPairs = responseData.Split('&');

            for (var i = 0; i < keyValPairs.Length; i++)
            {
                var splits = keyValPairs[i].Split('=');
                switch (splits[0])
                {
                    case "oauth_token":
                        request_token = splits[1];
                        break;
                    case "oauth_verifier":
                        oauth_verifier = splits[1];
                        break;
                }
            }

            var TwitterUrl = "https://api.twitter.com/oauth/access_token";

            var timeStamp = GetTimeStamp();
            var nonce = GetNonce();

            var SigBaseStringParams = "oauth_consumer_key=" + "ooWEcrlhooUKVOxSgsVNDJ1RK";
            SigBaseStringParams += "&" + "oauth_nonce=" + nonce;
            SigBaseStringParams += "&" + "oauth_signature_method=HMAC-SHA1";
            SigBaseStringParams += "&" + "oauth_timestamp=" + timeStamp;
            SigBaseStringParams += "&" + "oauth_token=" + request_token;
            SigBaseStringParams += "&" + "oauth_version=1.0";
            var SigBaseString = "POST&";
            SigBaseString += Uri.EscapeDataString(TwitterUrl) + "&" + Uri.EscapeDataString(SigBaseStringParams);

            var Signature = GetSignature(SigBaseString, "BtLpq9ZlFzXrFklC2f1CXqy8EsSzgRRVPZrKVh0imI2TOrZAan");

            var httpContent = new HttpStringContent("oauth_verifier=" + oauth_verifier, UnicodeEncoding.Utf8);
            httpContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
            var authorizationHeaderParams = "oauth_consumer_key=\"" + "ooWEcrlhooUKVOxSgsVNDJ1RK" + "\", oauth_nonce=\"" +
                                            nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"" +
                                            Uri.EscapeDataString(Signature) + "\", oauth_timestamp=\"" + timeStamp +
                                            "\", oauth_token=\"" + Uri.EscapeDataString(request_token) +
                                            "\", oauth_version=\"1.0\"";

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("OAuth",
                authorizationHeaderParams);
            var httpResponseMessage = await httpClient.PostAsync(new Uri(TwitterUrl), httpContent);
            var response = await httpResponseMessage.Content.ReadAsStringAsync();

            var Tokens = response.Split('&');
            string oauth_token_secret = null;
            string access_token = null;
            string screen_name = null;
            string user_id = null;

            for (var i = 0; i < Tokens.Length; i++)
            {
                var splits = Tokens[i].Split('=');
                switch (splits[0])
                {
                    case "screen_name":
                        screen_name = splits[1];
                        break;
                    case "oauth_token":
                        access_token = splits[1];
                        break;
                    case "oauth_token_secret":
                        oauth_token_secret = splits[1];
                        break;
                    case "user_id":
                        user_id = splits[1];
                        break;
                }
            }

            // Check if everything is fine AND do_SOCIAL__CNX
            if (user_id != null && access_token != null && oauth_token_secret != null)
            {
                var connec = new HttpRequestPost();
                var getKey = new HttpRequestGet();

                var key = await getKey.GetSocialToken(user_id, "twitter") as string;
                char[] delimiter = {' ', '"', '{', '}'};
                var word = key.Split(delimiter);
                var stringEncrypt = (user_id + word[4] + "3uNi@rCK$L$om40dNnhX)#jV2$40wwbr_bAK99%E");
                var sha256 = EncriptSha256.EncriptStringToSha256(stringEncrypt);
                await connec.ConnexionSocial("twitter", sha256, oauth_token_secret, user_id);
                var res = connec.Received;
                GetUser(res);
            }
        }
Esempio n. 2
0
        public async void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args)
        {
            ProgressOn = true;
            ObjFBHelper.ContinueAuthentication(args);
            if (ObjFBHelper.AccessToken != null)
            {
                fbclient = new FacebookClient(ObjFBHelper.AccessToken);
                Singleton.Singleton.Instance().MyFacebookClient = new FacebookClient(ObjFBHelper.AccessToken);

                dynamic result = await fbclient.GetTaskAsync("me");
                string id = result.id;

                var connecionSocial = new HttpRequestPost();
                var getKey = new HttpRequestGet();

                var key = await getKey.GetSocialToken(id, "facebook") as string;
                char[] delimiter = {' ', '"', '{', '}'};
                var word = key.Split(delimiter);
                var stringEncrypt = (id + word[4] + "3uNi@rCK$L$om40dNnhX)#jV2$40wwbr_bAK99%E");
                var sha256 = EncriptSha256.EncriptStringToSha256(stringEncrypt);

                await connecionSocial.ConnexionSocial("facebook", sha256, ObjFBHelper.AccessToken, id);
                var res = connecionSocial.Received;
                GetUser(res);
            }
        }