/// <summary>
        /// Creates an new instance of a request with the specified session.
        /// </summary>
        /// <param name="session">The session to use to issue the request.</param>
        public HyvesRequest(HyvesSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            this.session = session;
            parameters   = new HyvesRequestParameterList();
        }
        private static HttpWebRequest CreateRequest(string requestToken, string requestTokenSecret, HyvesExpirationType expirationType, HyvesSession session)
        {
            HyvesRequestParameterList parameters = new HyvesRequestParameterList();
            HyvesMethod method;

            if (string.IsNullOrEmpty(requestToken))
            {
                method = HyvesMethod.AuthRequesttoken;

                StringBuilder methodsStringBuilder = new StringBuilder();

                if (session.Methods.Contains(HyvesMethod.All))
                {
                    Array hyvesMethodValues = Enum.GetValues(typeof(HyvesMethod));
                    foreach (HyvesMethod hyvesMethod in hyvesMethodValues)
                    {
                        if (hyvesMethod != HyvesMethod.Unknown)
                        {
                            methodsStringBuilder.Append(string.Format("{0},", EnumHelper.GetDescription(hyvesMethod)));
                        }
                    }

                    methodsStringBuilder = methodsStringBuilder.Replace(
                        string.Format("{0},", EnumHelper.GetDescription(HyvesMethod.All)),
                        string.Empty);
                }
                else
                {
                    foreach (HyvesMethod hyvesMethod in session.Methods)
                    {
                        methodsStringBuilder.Append(string.Format("{0},", EnumHelper.GetDescription(hyvesMethod)));
                    }
                }

                string methods = methodsStringBuilder.ToString();
                parameters["methods"] = methods.Substring(0, methods.Length - 1);

                parameters["expirationtype"] = EnumHelper.GetDescription(expirationType);
            }
            else
            {
                session.InitializeToken(requestToken, requestTokenSecret, DateTime.MinValue);
                method = HyvesMethod.AuthAccesstoken;
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HyvesHttpUri);

            parameters.InitializeRequest(request, method, session);

            return(request);
        }
Exemple #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="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");
            }
        }
Exemple #4
0
 /// <summary>
 /// Generates a signature using the HMAC-SHA1 algorithm
 /// </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>
 /// <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)
 {
     return(GenerateSignature(url, parameters, consumerKey, consumerSecret, token, tokenSecret, httpMethod, timeStamp, nonce, SignatureTypes.HMACSHA1));
 }
Exemple #5
0
        /// <summary>
        /// Generate the signature base that is used to produce the signature
        /// </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 signature type. To use the default values use <see cref="OAuthBase.SignatureTypes">OAuthBase.SignatureTypes</see>.</param>
        /// <returns>The signature base</returns>
        public string GenerateSignatureBase(Uri url, HyvesRequestParameterList parameters, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureType)
        {
            if (token == null)
            {
                token = string.Empty;
            }

            if (tokenSecret == null)
            {
                tokenSecret = string.Empty;
            }

            if (string.IsNullOrEmpty(consumerKey))
            {
                throw new ArgumentNullException("consumerKey");
            }

            if (string.IsNullOrEmpty(consumerSecret))
            {
                throw new ArgumentNullException("consumerSecret");
            }

            if (string.IsNullOrEmpty(httpMethod))
            {
                throw new ArgumentNullException("httpMethod");
            }

            if (string.IsNullOrEmpty(signatureType))
            {
                throw new ArgumentNullException("signatureType");
            }

            List <QueryParameter> queryParameters = new List <QueryParameter>();

            /*List<QueryParameter> parameters = GetQueryParameters(url.Query);
             * parameters.Add(new QueryParameter(OAuthVersionKey, UrlEncode(OAuthVersion)));
             * parameters.Add(new QueryParameter(OAuthNonceKey, nonce));
             * parameters.Add(new QueryParameter(OAuthTimestampKey, timeStamp));
             * parameters.Add(new QueryParameter(OAuthSignatureMethodKey, UrlEncode(signatureType)));
             * parameters.Add(new QueryParameter(OAuthConsumerKeyKey, UrlEncode(consumerKey)));
             *
             * if (!string.IsNullOrEmpty(token))
             * {
             *      parameters.Add(new QueryParameter(OAuthTokenKey, UrlEncode(token)));
             * }*/

            foreach (KeyValuePair <string, string> param in parameters)
            {
                queryParameters.Add(new QueryParameter(param.Key, param.Value));
            }


            queryParameters.Sort(new QueryParameterComparer());

            string normalizedRequestParameters = NormalizeRequestParameters(queryParameters);

            StringBuilder signatureBase = new StringBuilder();

            signatureBase.AppendFormat("{0}&", httpMethod.ToUpper());
            signatureBase.AppendFormat("{0}&", UrlEncode(string.Format("{0}://{1}{2}", url.Scheme, url.Host, url.AbsolutePath)));
            signatureBase.AppendFormat("{0}", UrlEncode(normalizedRequestParameters));
            //signatureBase.AppendFormat("{0}&", UrlEncode(consumerSecret));
            //signatureBase.AppendFormat("{0}", UrlEncode(tokenSecret));

            return(signatureBase.ToString());
        }
        private static HttpWebRequest CreateRequest(HyvesMethod method, bool useFancyLayout, int page, int resultsPerPage, HyvesSession session, HyvesRequestParameterList parameters)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HyvesHttpUri);

            parameters.InitializeRequest(request, method, useFancyLayout, page, resultsPerPage, session);

            return(request);
        }
 private static HttpWebRequest CreateRequest(HyvesMethod method, bool useFancyLayout, HyvesSession session, HyvesRequestParameterList parameters)
 {
     return(CreateRequest(method, useFancyLayout, session, parameters));
 }
 private static HttpWebRequest CreateRequest(HyvesMethod method, HyvesSession session, HyvesRequestParameterList parameters)
 {
     return(CreateRequest(method, session, parameters));
 }