Exemple #1
0
        private void getOAuthRequestToken(string returnURL, TwitterSocialUserInfo twUserInfo)
        {
            Dictionary <string, string> oauthHeaderDictionary = new Dictionary <string, string>()
            {
                { OAUTH_CALLBACK_PARAMNAME, returnURL },
                { OAUTH_CONSUMERKEY_PARAMNAME, ClientCode },
                { OAUTH_NONCE_PARAMNAME, GenerateNonce() },
                { OAUTH_SIGNATUREMETHOD_PARAMNAME, OAUTH_SIGNATUREMETHOD_PARAMVALUE },
                { OAUTH_TIMESTAMP_PARAMNAME, MiscUtils.ToSecondsSinceUnixEpochStart(DateTime.Now).ToString() },
                { OAUTH_VERSION_PARAMNAME, OAUTH_VERSION_PARAMVALUE }
            };

            string rawOAuthHeaderStr   = GetRawOAuthHeaderStr(oauthHeaderDictionary);
            string requestStringToSign = AddMethodAndBaseURL(rawOAuthHeaderStr, HTTPRequestMethod.POST, OAUTH_REQUEST_TOKEN_URL);
            string signature           = CalculateSignature(requestStringToSign, ClientSecret);

            oauthHeaderDictionary.Add(OAUTH_SIGNATURE_PARAMNAME, signature);

            string oauthHeaderStr = "{0} {1}".Args(OAUTH_HEADER_NAME, GetOAuthHeaderString(oauthHeaderDictionary));

            var responseDictionary = WebClient.GetValueMap(OAUTH_REQUEST_TOKEN_URL, new WebClient.RequestParams(this)
            {
                Method  = HTTPRequestMethod.POST,
                Headers = new Dictionary <string, string>()
                {
                    { HttpRequestHeader.Authorization.ToString(), oauthHeaderStr }
                }
            });

            twUserInfo.OAuthRequestToken       = responseDictionary[OAUTH_TOKEN_PARAMNAME].AsString();
            twUserInfo.OAuthRequestTokenSecret = responseDictionary[OAUTH_TOKENSECRET_PARAMNAME].AsString();
        }
Exemple #2
0
        public override string GetSpecifiedExternalLoginReference(SocialUserInfo userInfo, string returnURL)
        {
            TwitterSocialUserInfo twitterUserInfo = userInfo as TwitterSocialUserInfo;

            string solializedReturnURL = PrepareReturnURLParameter(returnURL, false);

            getOAuthRequestToken(solializedReturnURL, twitterUserInfo);

            return(TWITTER_LOGIN_URL_PATTERN.Args(twitterUserInfo.OAuthRequestToken));
        }
Exemple #3
0
        // Gets user info.
        // For details see https://dev.twitter.com/rest/reference/get/users/show
        private void fillShowUserInfo(TwitterSocialUserInfo twUserInfo)
        {
            Dictionary <string, string> oauthHeaderDictionary = new Dictionary <string, string>()
            {
                { OAUTH_CONSUMERKEY_PARAMNAME, ClientCode },
                { OAUTH_NONCE_PARAMNAME, GenerateNonce() },
                { OAUTH_SIGNATUREMETHOD_PARAMNAME, OAUTH_SIGNATUREMETHOD_PARAMVALUE },
                { OAUTH_TIMESTAMP_PARAMNAME, MiscUtils.ToSecondsSinceUnixEpochStart(DateTime.Now).ToString() },
                { OAUTH_TOKEN_PARAMNAME, twUserInfo.OAuthAccessToken },
                { OAUTH_VERSION_PARAMNAME, OAUTH_VERSION_PARAMVALUE }
            };

            Dictionary <string, string> signDictionary = new Dictionary <string, string>(oauthHeaderDictionary);

            signDictionary.Add(USER_ID_PARAMNAME, twUserInfo.ID);

            string rawOAuthHeaderStr   = GetRawOAuthHeaderStr(signDictionary);
            string requestStringToSign = AddMethodAndBaseURL(rawOAuthHeaderStr, HTTPRequestMethod.GET, USER_SHOW_URL);
            string signature           = CalculateSignature(requestStringToSign, ClientSecret, twUserInfo.OAuthAccessTokenSecret);

            oauthHeaderDictionary.Add(OAUTH_SIGNATURE_PARAMNAME, signature);

            string oauthHeaderStr = "{0} {1}".Args(OAUTH_HEADER_NAME, GetOAuthHeaderString(oauthHeaderDictionary));

            dynamic response = WebClient.GetJsonAsDynamic(USER_SHOW_URL, new WebClient.RequestParams(this)
            {
                Method          = HTTPRequestMethod.GET,
                QueryParameters = new Dictionary <string, string>()
                {
                    { USER_ID_PARAMNAME, twUserInfo.ID }
                },
                Headers = new Dictionary <string, string>()
                {
                    { HttpRequestHeader.Authorization.ToString(), oauthHeaderStr }
                }
            });

            try
            {
                bool hasDefaultProfileImage = response[USER_DEFAULTPROFILEIMAGE_PARAMNAME];
                if (!hasDefaultProfileImage)
                {
                    twUserInfo.PictureLink = response[USER_PROFILEIMAGEURL_PARAMNAME].Replace("_normal.", ".");
                }

                twUserInfo.Locale = response[USER_LANG_PARAMNAME];

                twUserInfo.TimezoneOffset = (int?)response[USER_UTCOFFSET_PARAMNAME];
            }
            catch (Exception ex)
            {
                throw new NFXException(SocialStringConsts.POSTFAILED_ERROR + this.GetType().Name + ".twit", ex);
            }
        }
Exemple #4
0
        protected override void DoPostMessage(string text, SocialUserInfo userInfo)
        {
            if (userInfo.LoginState != SocialLoginState.LoggedIn)
            {
                return;
            }

            TwitterSocialUserInfo twitterUserInfo = userInfo as TwitterSocialUserInfo;

            twit(twitterUserInfo.OAuthAccessToken, twitterUserInfo.OAuthAccessTokenSecret, text);
        }
        public void SerializeDeserializeTWT()
        {
            using (var app = new ApplicationModel.TestApplication(m_RootCfg))
              {
            var ui = new TwitterSocialUserInfo(Twitter.Instance);

            initSocialUserInfo(ui);

            ui.UserName = "******";
            ui.OAuthRequestToken = "rMd67-J5c";
            ui.OAuthRequestTokenSecret = "brDM-00zeq6";
            ui.OAuthVerifier = "J78iOPz";

            var s = ui.SerializeToString();
            var ui1 = SocialUserInfo.DeserializeFromString<TwitterSocialUserInfo>(s);
            Assert.AreEqual(ui, ui1);
              }
        }
Exemple #6
0
        private void getOAuthAccessToken(TwitterSocialUserInfo twUserInfo)
        {
            Dictionary <string, string> oauthHeaderDictionary = new Dictionary <string, string>()
            {
                { OAUTH_CONSUMERKEY_PARAMNAME, ClientCode },
                { OAUTH_NONCE_PARAMNAME, GenerateNonce() },
                { OAUTH_SIGNATUREMETHOD_PARAMNAME, OAUTH_SIGNATUREMETHOD_PARAMVALUE },
                { OAUTH_TIMESTAMP_PARAMNAME, MiscUtils.ToSecondsSinceUnixEpochStart(DateTime.Now).ToString() },
                { OAUTH_TOKEN_PARAMNAME, twUserInfo.OAuthRequestToken },
                { OAUTH_VERSION_PARAMNAME, OAUTH_VERSION_PARAMVALUE }
            };

            Dictionary <string, string> signDictionary = new Dictionary <string, string>(oauthHeaderDictionary);

            signDictionary.Add(OAUTH_VERIFIER_PARAMNAME, twUserInfo.OAuthVerifier);

            string rawOAuthHeaderStr   = GetRawOAuthHeaderStr(signDictionary);
            string requestStringToSign = AddMethodAndBaseURL(rawOAuthHeaderStr, HTTPRequestMethod.POST, OAUTH_ACCESS_TOKEN_URL);
            string signature           = CalculateSignature(requestStringToSign, ClientSecret, twUserInfo.OAuthRequestTokenSecret);

            oauthHeaderDictionary.Add(OAUTH_SIGNATURE_PARAMNAME, signature);

            string oauthHeaderStr = "{0} {1}".Args(OAUTH_HEADER_NAME, GetOAuthHeaderString(oauthHeaderDictionary));

            var responseDictionary = WebClient.GetValueMap(OAUTH_ACCESS_TOKEN_URL, this, HTTPRequestMethod.POST,
                                                           bodyParameters: new Dictionary <string, string>()
            {
                { OAUTH_VERIFIER_PARAMNAME, twUserInfo.OAuthVerifier }
            },
                                                           headers: new Dictionary <string, string>()
            {
                { HttpRequestHeader.Authorization.ToString(), oauthHeaderStr }
            }
                                                           );

            twUserInfo.OAuthAccessToken       = responseDictionary[OAUTH_TOKEN_PARAMNAME].AsString();
            twUserInfo.OAuthAccessTokenSecret = responseDictionary[OAUTH_TOKENSECRET_PARAMNAME].AsString();
            twUserInfo.ID         = responseDictionary[USER_ID_PARAMNAME].AsString();
            twUserInfo.ScreenName = responseDictionary[USER_SCREENNAME_PARAMNAME].AsString();
        }
Exemple #7
0
      // Gets user info.
      // For details see https://dev.twitter.com/rest/reference/get/users/show
      private void fillShowUserInfo(TwitterSocialUserInfo twUserInfo)
      {
        Dictionary<string, string> oauthHeaderDictionary = new Dictionary<string, string>() { 
          {OAUTH_CONSUMERKEY_PARAMNAME, ClientCode},
          {OAUTH_NONCE_PARAMNAME, GenerateNonce()},
          {OAUTH_SIGNATUREMETHOD_PARAMNAME, OAUTH_SIGNATUREMETHOD_PARAMVALUE},
          {OAUTH_TIMESTAMP_PARAMNAME, MiscUtils.ToSecondsSinceUnixEpochStart(DateTime.Now).ToString()},
          {OAUTH_TOKEN_PARAMNAME, twUserInfo.OAuthAccessToken},
          {OAUTH_VERSION_PARAMNAME, OAUTH_VERSION_PARAMVALUE}
        };

        Dictionary<string, string> signDictionary = new Dictionary<string, string>(oauthHeaderDictionary);
        signDictionary.Add(USER_ID_PARAMNAME, twUserInfo.ID);

        string rawOAuthHeaderStr = GetRawOAuthHeaderStr(signDictionary);
        string requestStringToSign = AddMethodAndBaseURL(rawOAuthHeaderStr, HTTPRequestMethod.GET, USER_SHOW_URL);
        string signature = CalculateSignature(requestStringToSign, ClientSecret, twUserInfo.OAuthAccessTokenSecret);

        oauthHeaderDictionary.Add(OAUTH_SIGNATURE_PARAMNAME, signature);

        string oauthHeaderStr = "{0} {1}".Args(OAUTH_HEADER_NAME, GetOAuthHeaderString(oauthHeaderDictionary));

        dynamic response = WebClient.GetJson(USER_SHOW_URL, this, HTTPRequestMethod.GET,
          queryParameters: new Dictionary<string, string>() { { USER_ID_PARAMNAME, twUserInfo.ID } },
          headers: new Dictionary<string, string>() { { HttpRequestHeader.Authorization.ToString(), oauthHeaderStr } }
        );

        try
        {
          bool hasDefaultProfileImage = response[USER_DEFAULTPROFILEIMAGE_PARAMNAME];
          if (!hasDefaultProfileImage)
            twUserInfo.PictureLink = response[USER_PROFILEIMAGEURL_PARAMNAME];

          twUserInfo.Locale = response[USER_LANG_PARAMNAME];

          twUserInfo.TimezoneOffset = (int?)response[USER_UTCOFFSET_PARAMNAME];
        }
        catch (Exception ex)
        {
          throw new NFXException(SocialStringConsts.POSTFAILED_ERROR + this.GetType().Name + ".twit", ex);
        }
      }
Exemple #8
0
      private void getOAuthAccessToken(TwitterSocialUserInfo twUserInfo)
      {
        Dictionary<string, string> oauthHeaderDictionary = new Dictionary<string, string>() { 
          {OAUTH_CONSUMERKEY_PARAMNAME, ClientCode},
          {OAUTH_NONCE_PARAMNAME, GenerateNonce()},
          {OAUTH_SIGNATUREMETHOD_PARAMNAME, OAUTH_SIGNATUREMETHOD_PARAMVALUE},
          {OAUTH_TIMESTAMP_PARAMNAME, MiscUtils.ToSecondsSinceUnixEpochStart(DateTime.Now).ToString()},
          {OAUTH_TOKEN_PARAMNAME, twUserInfo.OAuthRequestToken},
          {OAUTH_VERSION_PARAMNAME, OAUTH_VERSION_PARAMVALUE}
        };

        Dictionary<string, string> signDictionary = new Dictionary<string,string>( oauthHeaderDictionary);
        signDictionary.Add(OAUTH_VERIFIER_PARAMNAME, twUserInfo.OAuthVerifier);

        string rawOAuthHeaderStr = GetRawOAuthHeaderStr(signDictionary);
        string requestStringToSign = AddMethodAndBaseURL(rawOAuthHeaderStr, HTTPRequestMethod.POST, OAUTH_ACCESS_TOKEN_URL);
        string signature = CalculateSignature(requestStringToSign, ClientSecret, twUserInfo.OAuthRequestTokenSecret);

        oauthHeaderDictionary.Add(OAUTH_SIGNATURE_PARAMNAME, signature);

        string oauthHeaderStr = "{0} {1}".Args(OAUTH_HEADER_NAME, GetOAuthHeaderString(oauthHeaderDictionary));

        var responseDictionary = WebClient.GetValueMap(OAUTH_ACCESS_TOKEN_URL, this, HTTPRequestMethod.POST, 
          bodyParameters: new Dictionary<string, string>() { { OAUTH_VERIFIER_PARAMNAME, twUserInfo.OAuthVerifier} },
          headers: new Dictionary<string, string>() { { HttpRequestHeader.Authorization.ToString(), oauthHeaderStr} }
        );

        twUserInfo.OAuthAccessToken = responseDictionary[OAUTH_TOKEN_PARAMNAME].AsString();
        twUserInfo.OAuthAccessTokenSecret = responseDictionary[OAUTH_TOKENSECRET_PARAMNAME].AsString();
        twUserInfo.ID = responseDictionary[USER_ID_PARAMNAME].AsString();
        twUserInfo.ScreenName = responseDictionary[USER_SCREENNAME_PARAMNAME].AsString();
      }