Ejemplo n.º 1
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public static string GenerateSignature(Uri url,
                                               string consumerKey,
                                               string consumerSecret,
                                               string token,
                                               string tokenSecret,
                                               string httpMethod,
                                               string timeStamp,
                                               string nonce,
                                               SignatureTypes signatureType)
        {
            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                return(HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));

            case SignatureTypes.HMACSHA1:
                string signatureBase = GenerateSignatureBase(
                    url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key =
                    Util.Utilities.GetBytesFromAsciiString(GenerateOAuthSignature(consumerSecret, tokenSecret));

                return(GenerateSignatureUsingHash(signatureBase, hmacsha1));

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token,
                                        string tokenSecret, string httpMethod, string timeStamp, string nonce,
                                        SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                return(HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));

            case SignatureTypes.HMACSHA1:
                string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));

                return(GenerateSignatureUsingHash(signatureBase, hmacsha1));

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="timeStamp">The time stamp.</param>
        /// <param name="nonce">The nonce.</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <param name="normalizedUrl">The normalized URL.</param>
        /// <param name="normalizedRequestParameters">The normalized request parameters.</param>
        /// <param name="authHeader">The auth header.</param>
        /// <returns>
        /// A base64 string of the hash value
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        /// <exception cref="System.ArgumentException">Unknown signature type;signatureType</exception>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token,
                                        string tokenSecret, string httpMethod, string timeStamp, string nonce,
                                        SignatureTypes signatureType, out string normalizedUrl,
                                        out string normalizedRequestParameters, out string authHeader)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;
            authHeader = null;

            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                var auth = new StringBuilder();
                auth.AppendFormat("{0}=\"{1}\", ", OAuthConsumerKeyKey, UrlEncode(consumerKey));
                auth.AppendFormat("{0}=\"{1}\", ", OAuthNonceKey, UrlEncode(nonce));
                auth.AppendFormat("{0}=\"{1}\", ", OAuthSignatureKey, UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));
                auth.AppendFormat("{0}=\"{1}\", ", OAuthSignatureMethodKey, "PLAINTEXT");
                auth.AppendFormat("{0}=\"{1}\", ", OAuthTimestampKey, timeStamp);
                if (!string.IsNullOrEmpty(token))
                {
                    auth.AppendFormat("{0}=\"{1}\", ", OAuthTokenKey, UrlEncode(token));
                }
                auth.AppendFormat("{0}=\"{1}\"", OAuthVersionKey, "1.0");
                authHeader = auth.ToString();
                return(UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 4
0
 public static string GenerateSignature(
     Uri url,
     string consumerKey,
     string consumerSecret,
     string token,
     string tokenSecret,
     string httpMethod,
     string timeStamp,
     string nonce,
     SignatureTypes signatureType,
     string version,
     Dictionary <string, string> bodyParams)
 {
     return(GenerateSignature(url,
                              consumerKey,
                              consumerSecret,
                              token,
                              tokenSecret,
                              httpMethod,
                              timeStamp,
                              nonce,
                              signatureType,
                              version,
                              bodyParams,
                              true,
                              false,
                              false));
 }
Ejemplo n.º 5
0
 public static string GenerateSignature(
     Uri url,
     string consumerKey,
     string consumerSecret,
     string token,
     string tokenSecret,
     string httpMethod,
     string timeStamp,
     string nonce,
     SignatureTypes signatureType,
     string version)
 {
     return(GenerateSignature(
                url,
                consumerKey,
                consumerSecret,
                token,
                tokenSecret,
                httpMethod,
                timeStamp,
                nonce,
                signatureType,
                version,
                null));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Generates a signature using the specified signatureType
 /// </summary>
 /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
 /// <param name="consumerKey">The consumer key</param>
 /// <param name="consumerSecret">The consumer seceret</param>
 /// <param name="token">The token, if available. If not available pass null or an empty string</param>
 /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
 /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
 /// <param name="signatureType">The type of signature to use</param>
 /// <returns>A base64 string of the hash value</returns>
 public static string GenerateSignature(
     Uri url,
     string consumerKey,
     string consumerSecret,
     string token,
     string tokenSecret,
     string httpMethod,
     string timeStamp,
     string nonce,
     SignatureTypes signatureType,
     string version,
     string bodyHash,
     Dictionary <string, string> bodyParams,
     bool standard,
     bool encodeRequestParameters,
     bool decodeUrlParameters)
 {
     return(GenerateSignature(
                url,
                consumerKey,
                consumerSecret,
                token,
                tokenSecret,
                httpMethod,
                timeStamp,
                nonce,
                signatureType,
                version,
                bodyHash,
                bodyParams,
                standard,
                encodeRequestParameters,
                decodeUrlParameters,
                false));
 }
Ejemplo n.º 7
0
 public static string GenerateSignature(
     Uri url,
     string consumerKey,
     string consumerSecret,
     string token,
     string tokenSecret,
     string httpMethod,
     string timeStamp,
     string nonce,
     SignatureTypes signatureType,
     bool standard,
     bool encodeRequestParameters,
     bool decodeUrlParameters)
 {
     return(GenerateSignature(
                url,
                consumerKey,
                consumerSecret,
                token,
                tokenSecret,
                httpMethod,
                timeStamp,
                nonce,
                signatureType,
                OAuthVersion,
                standard,
                encodeRequestParameters,
                decodeUrlParameters));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Generates a signature using the specified signatureType 
        /// </summary>		
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
                case SignatureTypes.PLAINTEXT:
                    return WebUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
                case SignatureTypes.HMACSHA1:
                    var signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);

                    var value = string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret));
                    var algorithm = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1);
                    var keymaterial = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8);
                    var hmacKey = algorithm.CreateKey(keymaterial);

                    var signature = GenerateSignatureUsingHash(signatureBase, hmacKey);
                    return CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, signature);
                case SignatureTypes.RSASHA1:
                    throw new NotImplementedException();
                default:
                    throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Google OAuth 1.0 client.
 /// </summary>
 /// <param name="consumerKey">The unique consumer key.</param>
 /// <param name="consumerSecret">The consumer secret used for signing</param>
 /// <param name="signatureTypes">The signature type.</param>
 /// <param name="callBackUri">The call back URI</param>
 public Google(string consumerKey, string consumerSecret, SignatureTypes signatureTypes, Uri callBackUri) :
     this(consumerKey, consumerSecret, signatureTypes,
          new Uri("https://www.google.com/accounts/OAuthGetRequestToken"),
          new Uri("https://www.google.com/accounts/OAuthAuthorizeToken"),
          new Uri("https://www.google.com/accounts/OAuthGetAccessToken"),
          callBackUri)
 {
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Twitter OAuth 1.0 client.
        /// </summary>
        /// <param name="consumerKey">The unique consumer key.</param>
        /// <param name="consumerSecret">The consumer secret used for signing</param>
        /// <param name="signatureTypes">The signature type.</param>
        /// <param name="requestTokenUri">The request token URI</param>
        /// <param name="userAuthorizeUri">The user authorize URI</param>
        /// <param name="accessTokenUri">The access token URI</param>
        /// <param name="callBackUri">The call back URI</param>
        public Twitter(string consumerKey, string consumerSecret, SignatureTypes signatureTypes, Uri requestTokenUri, Uri userAuthorizeUri, Uri accessTokenUri, Uri callBackUri) :
            base(consumerKey, consumerSecret, signatureTypes, requestTokenUri, userAuthorizeUri, accessTokenUri, callBackUri)
        {
            OnCreated();

            // Twitter can't handle the Expect 100 Continue HTTP header.
            ServicePointManager.FindServicePoint(new Uri(GetFavoritesEndpoint)).Expect100Continue = false;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Twitter OAuth 1.0 client.
 /// </summary>
 /// <param name="consumerKey">The unique consumer key.</param>
 /// <param name="consumerSecret">The consumer secret used for signing</param>
 /// <param name="signatureTypes">The signature type.</param>
 /// <param name="callBackUri">The call back URI</param>
 public Twitter(string consumerKey, string consumerSecret, SignatureTypes signatureTypes, Uri callBackUri) :
     this(consumerKey, consumerSecret, signatureTypes,
          new Uri("http://twitter.com/oauth/request_token"),
          new Uri("http://twitter.com/oauth/authorize"),
          new Uri("http://twitter.com/oauth/access_token"),
          callBackUri)
 {
 }
Ejemplo n.º 12
0
 public GenerateValuesRequest(string consumerKey, string consumerSecretKey, string tokenKey, string tokenSecretKey, SignatureTypes signatureType, bool includeVersion, string version = "1.0")
 {
     OAuthVersion      = version;
     ConsumerKey       = consumerKey;
     ConsumerSecretKey = consumerSecretKey;
     TokenKey          = tokenKey;
     TokenSecretKey    = tokenSecretKey;
     IncludeVersion    = includeVersion;
     SignatureType     = signatureType;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">
        /// The full url that needs to be signed including its non OAuth url parameters
        /// </param>
        /// <param name="consumerKey">
        /// The consumer key
        /// </param>
        /// <param name="consumerSecret">
        /// The consumer seceret
        /// </param>
        /// <param name="token">
        /// The token, if available. If not available pass null or an empty string
        /// </param>
        /// <param name="tokenSecret">
        /// The token secret, if available. If not available pass null or an empty string
        /// </param>
        /// <param name="callBackUrl">
        /// The call Back Url.
        /// </param>
        /// <param name="httpMethod">
        /// The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)
        /// </param>
        /// <param name="timeStamp">
        /// The time Stamp.
        /// </param>
        /// <param name="nonce">
        /// The nonce.
        /// </param>
        /// <param name="pin">
        /// The PIN.
        /// </param>
        /// <param name="signatureType">
        /// The type of signature to use
        /// </param>
        /// <param name="normalizedUrl">
        /// The normalized Url.
        /// </param>
        /// <param name="normalizedRequestParameters">
        /// The normalized Request Parameters.
        /// </param>
        /// <returns>
        /// A base64 string of the hash value
        /// </returns>
        /// <exception cref="ArgumentException">Unknown signature type</exception>
        public string GenerateSignature(
            Uri url,
            string consumerKey,
            string consumerSecret,
            string token,
            string tokenSecret,
            string callBackUrl,
            string httpMethod,
            string timeStamp,
            string nonce,
            string pin,
            SignatureTypes signatureType,
            out string normalizedUrl,
            out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                return(HttpUtility.UrlEncode("{0}&{1}".FormatWith(consumerSecret, tokenSecret)));

            case SignatureTypes.HMACSHA1:
                string signatureBase = this.GenerateSignatureBase(
                    url,
                    consumerKey,
                    token,
                    tokenSecret,
                    callBackUrl,
                    httpMethod,
                    timeStamp,
                    nonce,
                    pin,
                    HMACSHA1SignatureType,
                    out normalizedUrl,
                    out normalizedRequestParameters);

                HMACSHA1 hmacsha1 = new HMACSHA1
                {
                    Key =
                        Encoding.ASCII.GetBytes(
                            "{0}&{1}".FormatWith(
                                this.UrlEncode(consumerSecret),
                                string.IsNullOrEmpty(tokenSecret)
                                                            ? string.Empty
                                                            : this.UrlEncode(tokenSecret)))
                };

                return(this.GenerateSignatureUsingHash(signatureBase, hmacsha1));

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 14
0
        public static void SetSignatureInRegistry(string signatureName, SignatureTypes signatureType, int officeVersion)
        {
            var keyName     = $"Software\\Microsoft\\Office\\{officeVersion}.0\\Common\\MailSettings";
            var registryKey = Registry.CurrentUser.OpenSubKey(keyName, true) ?? throw new Exception($"The key HKCU:\\{keyName} was not found.");

            if (signatureType == (SignatureTypes.NewSignature | SignatureTypes.ReplySignature))
            {
                registryKey.SetValue(nameof(SignatureTypes.NewSignature), signatureName, RegistryValueKind.String);
                registryKey.SetValue(nameof(SignatureTypes.ReplySignature), signatureName, RegistryValueKind.String);
            }
            registryKey.SetValue(signatureType.ToString(), signatureName, RegistryValueKind.String);
        }
Ejemplo n.º 15
0
        public static string SomeMethod(this SignatureTypes enumValue)
        {
            FieldInfo fieldInfo = enumValue.GetType().GetField(enumValue.ToString());

            if (fieldInfo == null)
            {
                return(null);
            }
            var attribute = (DescriptionAttribute)fieldInfo.GetCustomAttribute(typeof(DescriptionAttribute));

            return(attribute.Description);
        }
Ejemplo n.º 16
0
        //TODO CCOLE
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <param name="allowOauthCallbackParameter">Legacy support of MyspaceID SDK where oauth_callback value is signed</param>
        /// <returns>A base64 string of the hash value</returns>
        public static string GenerateSignature(
            Uri url,
            string consumerKey,
            string consumerSecret,
            string token,
            string tokenSecret,
            string httpMethod,
            string timeStamp,
            string nonce,
            SignatureTypes signatureType,
            string version,
            string bodyHash,
            Dictionary <string, string> bodyParams,
            bool standard,
            bool encodeRequestParameters,
            bool decodeUrlParameters,
            bool allowOauthCallbackParameter)
        {
            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                return(HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));

            case SignatureTypes.HMACSHA1:
                string signatureBase = GenerateSignatureBase(
                    url,
                    consumerKey,
                    token,
                    tokenSecret,
                    httpMethod,
                    timeStamp,
                    nonce,
                    HMACSHA1SignatureType,
                    version,
                    bodyHash,
                    bodyParams,
                    standard,
                    encodeRequestParameters,
                    decodeUrlParameters,
                    allowOauthCallbackParameter);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key = Encoding.UTF8.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), UrlEncode(tokenSecret)));

                return(GenerateSignatureUsingHash(signatureBase, hmacsha1));

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(
            Uri url,
            string consumerKey,
            string consumerSecret,
            string token,
            string tokenSecret,
            string httpMethod,
            string timeStamp,
            string nonce,
            SignatureTypes signatureType,
            out string normalizedUrl,
            out string normalizedRequestParameters,
            out string authHeader
            )
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;
            authHeader = null;

            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                return(UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));

            case SignatureTypes.HMACSHA1:
                string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));

                string signature = GenerateSignatureUsingHash(signatureBase, hmacsha1);

                StringBuilder auth = new StringBuilder();
                auth.AppendFormat("{0}=\"{1}\", ", OAuthConsumerKeyKey, UrlEncode(consumerKey));
                auth.AppendFormat("{0}=\"{1}\", ", OAuthNonceKey, UrlEncode(nonce));
                auth.AppendFormat("{0}=\"{1}\", ", OAuthSignatureKey, UrlEncode(signature));
                auth.AppendFormat("{0}=\"{1}\", ", OAuthSignatureMethodKey, "HMAC-SHA1");
                auth.AppendFormat("{0}=\"{1}\", ", OAuthTimestampKey, timeStamp);
                auth.AppendFormat("{0}=\"{1}\", ", OAuthTokenKey, UrlEncode(token));
                auth.AppendFormat("{0}=\"{1}\"", OAuthVersionKey, "1.0");
                authHeader = auth.ToString();

                return(signature);

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Auth consumer interface implementation.
        /// </summary>
        /// <param name="consumerKey">The unique consumer key.</param>
        /// <param name="consumerSecret">The consumer secret used for signing</param>
        /// <param name="signatureTypes">The signature type.</param>
        /// <param name="requestTokenUri">The request token URI</param>
        /// <param name="userAuthorizeUri">The user authorize URI</param>
        /// <param name="accessTokenUri">The access token URI</param>
        /// <param name="callBackUri">The call back URI</param>
        /// <param name="certificate">The certificate issued by the provider; only used when SignatureTypes = RSA_SHA1.</param>
        public AuthConsumer(string consumerKey, string consumerSecret, SignatureTypes signatureTypes,
                            Uri requestTokenUri, Uri userAuthorizeUri, Uri accessTokenUri, Uri callBackUri = null, X509Certificate2 certificate = null)
        {
            _consumerKey      = consumerKey;
            _consumerSecret   = consumerSecret;
            _signatureTypes   = signatureTypes;
            _requestTokenUri  = requestTokenUri;
            _userAuthorizeUri = userAuthorizeUri;
            _accessTokenUri   = accessTokenUri;
            _certificate      = certificate;
            _callBackUri      = callBackUri;

            // Validate all the parameters
            Validate();

            OnCreated();
        }
Ejemplo n.º 19
0
        static private String GetSignatureTypeString(SignatureTypes type)
        {
            switch (type)
            {
            case SignatureTypes.HMACSHA1:
                return("HMACSHA1");

            case SignatureTypes.PLAINTEXT:
                return("PLAINTEXT");

            case SignatureTypes.RSASHA1:
                return("RSASHA1");

            default:
                return("");
            }
        }
Ejemplo n.º 20
0
        public static string GetDescription(this SignatureTypes enumValue)
        {
            var retorno = "";

            switch (enumValue)
            {
            case SignatureTypes.HMAC_SHA1:
                retorno = "HMAC-SHA1";
                break;

            case SignatureTypes.PLAINTEXT:
                retorno = "PLAINTEXT";
                break;

            case SignatureTypes.RSA_SHA1:
                retorno = "RSA-SHA1";
                break;
            }

            return(retorno);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="nonce"></param>
        /// <param name="signatureType">The Type of signature to use</param>
        /// <param name="normalizedUrl"></param>
        /// <param name="normalizedRequestParameters"></param>
        /// <param name="timeStamp"></param>
        /// <returns>A base64 string of the hash value</returns>
        private string GenerateSignature(
            Uri url,
            string consumerKey,
            string consumerSecret,
            string token,
            string tokenSecret,
            string httpMethod,
            string timeStamp,
            string nonce,
            SignatureTypes signatureType,
            out string normalizedUrl,
            out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
            case SignatureTypes.Plaintext:
                return(HttpUtility.UrlEncode($"{consumerSecret}&{tokenSecret}"));

            case SignatureTypes.Hmacsha1:
                string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod,
                                                             timeStamp, nonce, Hmacsha1SignatureType, out normalizedUrl, out normalizedRequestParameters);

                using (var hmacsha1 = new HMACSHA1())
                {
                    hmacsha1.Key =
                        Encoding.ASCII.GetBytes(
                            $"{UrlEncode(consumerSecret)}&{(string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret))}");
                    return(GenerateSignatureUsingHash(signatureBase, hmacsha1));
                }

            case SignatureTypes.Rsasha1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature Type", nameof(signatureType));
            }
        }
Ejemplo n.º 22
0
        public Result <string> Calculate(IDictionary <string, string> model, SignatureTypes type)
        {
            if (!Enum.IsDefined(typeof(SignatureTypes), type) || type == SignatureTypes.Unknown)
            {
                return(Result.Failure <string>("Invalid signature type"));
            }

            var pass           = type == SignatureTypes.Request ? _options.ShaRequestPhrase : _options.ShaResponsePhrase;
            var filteredValues = model
                                 .Where(kv => kv.Key != "signature" && kv.Value != null)
                                 .OrderBy(kv => kv.Key)
                                 .Select(kv => $"{kv.Key}={kv.Value}");

            var str = $"{pass}{string.Join("", filteredValues)}{pass}";

            using (var sha = SHA512.Create())
            {
                var bytes = Encoding.UTF8.GetBytes(str);
                var hash  = sha.ComputeHash(bytes);
                return(Result.Success(BitConverter.ToString(hash).Replace("-", string.Empty).ToLower()));
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public string BuildOAuth(string url, string consumerKey, string consumerSecret, string token, string tokenSecret, HttpMethod httpMethod
                                 , string timeStamp, string nonce, SignatureTypes signatureType)
        {
            OAuthBase oAuthBase     = new OAuthBase();
            string    normalizedUrl = string.Empty;
            string    normalizedRequestParameters = string.Empty;

            OAuthBase.SignatureTypes OAuthBaseSignatureTypes = OAuthBase.SignatureTypes.PLAINTEXT;

            if (signatureType == SignatureTypes.HMACSHA1)
            {
                OAuthBaseSignatureTypes = OAuthBase.SignatureTypes.HMACSHA1;
            }


            string oauth_signature = oAuthBase.GenerateSignature(new Uri(url), consumerKey, consumerSecret
                                                                 , token, tokenSecret, httpMethod.ToString(), timeStamp, nonce, OAuthBaseSignatureTypes, string.Empty, out normalizedUrl, out normalizedRequestParameters);



            return(oAuthBase.Header(new Uri(url), consumerKey, token, timeStamp, nonce, OAuthBaseSignatureTypes, string.Empty, oauth_signature));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <param name="callback"></param>
        /// <param name="nonce"></param>
        /// <param name="normalizedRequestParameters"></param>
        /// <param name="normalizedUrl"></param>
        /// <param name="timeStamp"></param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string callback, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT: // FIXME: Is this correct?
                return(WebUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)));

            case SignatureTypes.HMACSHA1:
                string signatureBase = GenerateSignatureBase(url, consumerKey, callback, token, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);
                Log("Signaturebase: " + signatureBase);

                string key = string.Format("{0}&{1}", UrlEncode(Encoder8bit.GetString(Encoding.UTF8.GetBytes(consumerSecret ?? ""))),
                                           UrlEncode(Encoder8bit.GetString(Encoding.UTF8.GetBytes(tokenSecret ?? ""))));
                Log("Signature key: " + key);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key = Encoder8bit.GetBytes(key);

                return(GenerateSignatureUsingHash(signatureBase, hmacsha1));

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 25
0
 public Signature(SignatureTypes type, string signature)
 {
     Type = type;
     Name = signature;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, HyvesRequestParameterList parameters, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType)
        {
            switch (signatureType)
            {
            case SignatureTypes.HMACSHA1:
                string signatureBase = GenerateSignatureBase(url, parameters, consumerKey, consumerSecret, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), UrlEncode(tokenSecret)));

                return(GenerateSignatureUsingHash(signatureBase, hmacsha1));

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 27
0
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string verifier, string httpMethod, string timeStamp, string nonce, string callback, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;
            switch (signatureType)
            {
            case SignatureTypes.Hmacsha1:
                var signatureBase = GenerateSignatureBase(url, consumerKey, token, verifier, httpMethod, timeStamp, nonce, callback, Hmacsha1SignatureType, out normalizedUrl, out normalizedRequestParameters);
                var hmacshA1      = new HMACSHA1
                {
                    Key = Encoding.ASCII.GetBytes($"{UrlEncode(consumerSecret)}&{UrlEncode(verifier)}")
                };
                return(GenerateSignatureUsingHash(signatureBase, hmacshA1));

            case SignatureTypes.Plaintext:
                GenerateSignatureBase(url, consumerKey, token, verifier, httpMethod, timeStamp, nonce, callback, PlainTextSignatureType, out normalizedUrl, out normalizedRequestParameters);
                return(HttpUtility.UrlEncode($"{consumerSecret}&{verifier}"));

            case SignatureTypes.Rsasha1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException(@"Unknown signature type", nameof(signatureType));
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Generates a signature using the specified signatureType 
        /// </summary>		
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <param name="callback"></param>
        /// <param name="nonce"></param>
        /// <param name="normalizedRequestParameters"></param>
        /// <param name="normalizedUrl"></param>
        /// <param name="timeStamp"></param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string callback, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
              normalizedRequestParameters = null;

              switch (signatureType)
              {
            case SignatureTypes.PLAINTEXT: // FIXME: Is this correct?
              return HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
            case SignatureTypes.HMACSHA1:
              string signatureBase = GenerateSignatureBase(url, consumerKey, callback, token, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);
              Log("Signaturebase: " + signatureBase);

              string key = string.Format("{0}&{1}", UrlEncode(Encoder8bit.GetString(Encoding.UTF8.GetBytes(consumerSecret ?? ""))),
                                                UrlEncode(Encoder8bit.GetString(Encoding.UTF8.GetBytes(tokenSecret ?? ""))));
              Log("Signature key: " + key);

              HMACSHA1 hmacsha1 = new HMACSHA1();
              hmacsha1.Key = Encoder8bit.GetBytes(key);

              return GenerateSignatureUsingHash(signatureBase, hmacsha1);
            case SignatureTypes.RSASHA1:
              throw new NotImplementedException();
            default:
              throw new ArgumentException("Unknown signature type", "signatureType");
              }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Generates a signature using the specified signatureType 
        /// </summary>		
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string userName, string password, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
                case SignatureTypes.PLAINTEXT:
                    return HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
                case SignatureTypes.HMACSHA1:
                    string toBeSigned = GenerateSignatureBase(url, consumerKey, consumerSecret, token, tokenSecret, userName, password, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);

                    string signedSecret = UrlEncode(consumerSecret)+"&" ;//
                    if (!String.IsNullOrEmpty(token) && !String.IsNullOrEmpty(tokenSecret))
                        signedSecret += UrlEncode(tokenSecret) + "&";

                    byte[] key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));
                   // byte[] key = Encoding.ASCII.GetBytes(signedSecret);
                    byte[] message = Encoding.ASCII.GetBytes(toBeSigned);

                    HMACSHA1 hmacsha1 = new HMACSHA1();
                    hmacsha1.Key = key;
                    byte[] hash = hmacsha1.ComputeHash(message);

                    string base64hash = Convert.ToBase64String(hash);

                    return base64hash;
                case SignatureTypes.RSASHA1:
                    throw new NotImplementedException();
                default:
                    throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Generates a signature using the specified signatureType
 /// </summary>
 /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
 /// <param name="consumerKey">The consumer key</param>
 /// <param name="consumerSecret">The consumer seceret</param>
 /// <param name="token">The token, if available. If not available pass null or an empty string</param>
 /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
 /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
 /// <param name="signatureType">The type of signature to use</param>
 /// <returns>A base64 string of the hash value</returns>
 public string BuildOAuth(string url, string consumerKey, string consumerSecret, HttpMethod httpMethod, SignatureTypes signatureTypes)
 {
     return(BuildOAuth(url, consumerKey, consumerSecret, string.Empty, string.Empty, httpMethod, GenerateTimeStamp(), GenerateNonce(), signatureTypes));
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Auth consumer interface implementation.
 /// </summary>
 /// <param name="consumerKey">The unique consumer key.</param>
 /// <param name="consumerSecret">The consumer secret used for signing</param>
 /// <param name="signatureTypes">The signature type.</param>
 /// <param name="requestTokenUri">The request token URI</param>
 /// <param name="userAuthorizeUri">The user authorize URI</param>
 /// <param name="accessTokenUri">The access token URI</param>
 /// <param name="certificate">The certificate issued by the provider; only used when SignatureTypes = RSA_SHA1.</param>
 public AuthConsumer(string consumerKey, string consumerSecret, SignatureTypes signatureTypes,
                     Uri requestTokenUri, Uri userAuthorizeUri, Uri accessTokenUri, X509Certificate2 certificate)
     : this(consumerKey, consumerSecret, signatureTypes, requestTokenUri, userAuthorizeUri, accessTokenUri, null, certificate)
 {
 }
Ejemplo n.º 32
0
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType)
        {
            switch (signatureType)
            {
                case SignatureTypes.PLAINTEXT:
                    return HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));

                case SignatureTypes.HMACSHA1:
                    string signatureBase = GenerateSignatureBase(url, consumerKey, consumerSecret, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType);

                    HMACSHA1 hmacsha1 = new HMACSHA1();

                    string data = string.Format("{0}&", consumerSecret);

                    if (tokenSecret != string.Empty || tokenSecret != null)
                    {
                        data = string.Format("{0}&{1}", consumerSecret, tokenSecret);
                    }

                    hmacsha1.Key = Encoding.UTF8.GetBytes(data);
                    return GenerateSignatureUsingHash(signatureBase, hmacsha1);

                case SignatureTypes.RSASHA1:
                    throw new NotImplementedException();
                default:
                    throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <returns>A base64 string of the hash value</returns>
        public Uri GenerateAuthenticatedUrl(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, SignatureTypes signatureType)
        {
            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                return(new Uri(HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret))));

            case SignatureTypes.HMACSHA1:
                var urlParts = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, HMACSHA1SignatureType);

                HMACSHA1 hmacsha1 = new HMACSHA1();
                hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));

                return(new Uri($"{urlParts.RootUrl}?oauth_signature={GenerateSignatureUsingHash(urlParts.Signature, hmacsha1)}&{urlParts.Parameters}"));

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Generates a signature using the specified signatureType 
        /// </summary>		
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty string</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
        /// <param name="callBackUrl">The callback URL (for OAuth 1.0a).If your client cannot accept callbacks, the value MUST be 'oob' </param>
        /// <param name="oauthVerifier">This value MUST be included when exchanging Request Tokens for Access Tokens. Otherwise pass a null or an empty string</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="nonce"> </param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <param name="timeStamp"> </param>
        /// <param name="normalizedUrl"> </param>
        /// <param name="normalizedRequestParameters"> </param>
        /// <returns>A base64 string of the hash value</returns>
        public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token,
                                        string tokenSecret, string callBackUrl, string oauthVerifier, string httpMethod,
                                        string timeStamp, string nonce, SignatureTypes signatureType,
                                        out string normalizedUrl, out string normalizedRequestParameters)
        {
            normalizedUrl = null;
            normalizedRequestParameters = null;

            switch (signatureType)
            {
                case SignatureTypes.PLAINTEXT:
                    return HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
                case SignatureTypes.HMACSHA1:
                    string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, callBackUrl,
                                                                 oauthVerifier, httpMethod, timeStamp, nonce,
                                                                 HMACSHA1_SIGNATURE_TYPE, out normalizedUrl,
                                                                 out normalizedRequestParameters);

                    var hmacsha1 = new HMACSHA1();
                    hmacsha1.Key =
                        Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret),
                                                              string.IsNullOrEmpty(tokenSecret)
                                                                  ? ""
                                                                  : UrlEncode(tokenSecret)));

                    return GenerateSignatureUsingHash(signatureBase, hmacsha1);
                case SignatureTypes.RSASHA1:
                    throw new NotImplementedException();
                default:
                    throw new ArgumentException("Unknown signature type", "signatureType");
            }
        }
Ejemplo n.º 35
0
 static private String GetSignatureTypeString( SignatureTypes type )
 {
     switch(type)
     {
         case SignatureTypes.HMACSHA1:
             return "HMACSHA1";
         case SignatureTypes.PLAINTEXT:
             return "PLAINTEXT";
         case SignatureTypes.RSASHA1:
             return "RSASHA1";
         default:
             return "";
     }
 }
Ejemplo n.º 36
0
 public Signature(SignatureTypes type, string signature)
 {
     Type = type;
     Name = signature;
 }
Ejemplo n.º 37
0
        public string Header(Uri url, string consumerKey, string token, string timeStamp, string nonce, SignatureTypes signatureType, string verifier, string signature)
        {
            List <QueryParameter> parameters = GetQueryParameters(url.Query);

            parameters.Add(new QueryParameter(OAuthVersionKey, OAuthVersion));
            parameters.Add(new QueryParameter(OAuthNonceKey, nonce));
            parameters.Add(new QueryParameter(OAuthTimestampKey, timeStamp));
            switch (signatureType)
            {
            case SignatureTypes.HMACSHA1:
                parameters.Add(new QueryParameter(OAuthSignatureMethodKey, HMACSHA1SignatureType));
                break;

            case SignatureTypes.PLAINTEXT:
                parameters.Add(new QueryParameter(OAuthSignatureMethodKey, PlainTextSignatureType));
                break;

            case SignatureTypes.RSASHA1:
                parameters.Add(new QueryParameter(OAuthSignatureMethodKey, RSASHA1SignatureType));
                break;

            default:
                break;
            }

            parameters.Add(new QueryParameter(OAuthConsumerKeyKey, consumerKey));

            if (!string.IsNullOrEmpty(token))
            {
                parameters.Add(new QueryParameter(OAuthTokenKey, token));
            }

            if (!string.IsNullOrEmpty(verifier))
            {
                parameters.Add(new QueryParameter(OAuthVerifier, verifier));
            }

            parameters = parameters.OrderBy(d => d.Name).OrderBy(d => d.Value).ToList();

            parameters.Add(new QueryParameter(OAuthSignatureKey, signature));

            StringBuilder AuthParam = new StringBuilder();

            AuthParam.Append("OAuth ");
            AuthParam.Append("realm=\"\",");
            foreach (var p in parameters)
            {
                AuthParam.AppendFormat("{0}=\"{1}\",", p.Name, p.Value);
            }


            return(AuthParam.ToString(0, AuthParam.Length - 1));
        }