Beispiel #1
0
        private string GetOauthHeader(OauthHeaderType oauthHeaderType, string bearerToken, OAuthSocialNetwork network)
        {
            switch (network)
            {
            case OAuthSocialNetwork.Twitter:
            case OAuthSocialNetwork.LinkedIn:
                return(oauthHeaderType.ToString() + " " + bearerToken);

            case OAuthSocialNetwork.FaceBook:
                return(string.Empty);

            default:
                return(oauthHeaderType.ToString() + " " + bearerToken);
            }
        }
        private string GetOauthHeader(OauthAuthentication oauthentication, OauthHeaderType oauthHeaderType)
        {
            var oauth_version          = "1.0";
            var oauth_signature_method = "HMAC-SHA1";
            var oauth_nonce            = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));

            var timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0,
                                                          DateTimeKind.Utc);
            var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();

            var baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                             "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}";

            var baseString = string.Format(baseFormat,
                                           oauthentication.ConsumerKey,
                                           oauth_nonce,
                                           oauth_signature_method,
                                           oauth_timestamp,
                                           oauthentication.TokenKey,
                                           oauth_version
                                           );


            var compositeKey = string.Concat(Uri.EscapeDataString(oauthentication.ConsumerSecret),
                                             "&", Uri.EscapeDataString(oauthentication.TokenSecret));

            string oauth_signature;

            using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
            {
                oauth_signature = Convert.ToBase64String(
                    hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
            }

            var headerFormat = oauthentication.ConsumerKey + ":" + oauthentication.ConsumerSecret;

            headerFormat = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(headerFormat));

            return(oauthHeaderType.ToString() + " " + headerFormat);
        }
 private string GetOauthHeader(OauthHeaderType oauthHeaderType, string bearerToken)
 {
     return(oauthHeaderType.ToString() + " " + bearerToken);
 }
Beispiel #4
0
        private string GetOauthHeader(OauthAuthentication oauthentication, OauthHeaderType oauthHeaderType,
                                      OAuthSocialNetwork network)
        {
            var oauth_version          = "1.0";
            var oauth_signature_method = "HMAC-SHA1";
            var oauth_nonce            = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));

            var timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0,
                                                          DateTimeKind.Utc);
            var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();

            var baseFormat = string.Empty;
            var baseString = string.Empty;

            if (network.Equals(OAuthSocialNetwork.Twitter))
            {
                baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                             "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}";
                baseString = string.Format(baseFormat,
                                           oauthentication.ConsumerKey,
                                           oauth_nonce,
                                           oauth_signature_method,
                                           oauth_timestamp,
                                           oauthentication.TokenKey,
                                           oauth_version
                                           );
            }
            else if (network.Equals(OAuthSocialNetwork.LinkedIn))
            {
                baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                             "&oauth_timestamp={3}&oauth_callback={4}&oauth_version={5}&client_id={6}&redirect_uri={7}&scope=r_fullprofile%20w_share&state=MezZanillionsxein2859";
                baseString = string.Format(baseFormat,
                                           oauthentication.ConsumerKey,
                                           oauth_nonce,
                                           oauth_signature_method,
                                           oauth_timestamp,
                                           HttpContext.Current.Request.Url.AbsoluteUri,
                                           oauth_version,
                                           oauthentication.ClientAppId,
                                           HttpContext.Current.Request.Url.AbsoluteUri
                                           );
            }



            var compositeKey = string.Concat(Uri.EscapeDataString(oauthentication.ConsumerSecret),
                                             "&", Uri.EscapeDataString(oauthentication.TokenSecret));

            string oauth_signature;

            using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
            {
                oauth_signature = Convert.ToBase64String(
                    hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
            }

            var headerFormat = oauthentication.ConsumerKey + ":" + oauthentication.ConsumerSecret;

            headerFormat = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(headerFormat));

            return(oauthHeaderType.ToString() + " " + headerFormat);
        }