예제 #1
0
        /// <summary>
        /// Generate the signature base that is used to produce the signature
        /// </summary>
        /// <param name="oauth">The full url that needs to be signed </param>
        /// <param name="extraParameters">The parameters</param>
        private SignatureResult GenerateSignatureBase(OAuthInfomation oauth, QueryParameterList extraParameters)
        {
            if (oauth.Token == null)
            {
                oauth.Token = String.Empty;
            }

            if (oauth.TokenSecret == null)
            {
                oauth.TokenSecret = String.Empty;
            }

            var result = new SignatureResult();

            var parameters = GetQueryParameters(oauth.RequestUri.Query);

            parameters.AddRange(oauth.GetParametersForSignature());
            parameters.AddRange(extraParameters.Where(p => p.NeedSign));
            parameters.Sort(new QueryParameterComparer());

            var signatureBase = new StringBuilder();

            signatureBase.AppendFormat("{0}&", oauth.HttpMethod.ToUpper());
            signatureBase.AppendFormat("{0}&", UrlEncode(oauth.RequestUri.Normalize()));
            signatureBase.AppendFormat("{0}", UrlEncode(parameters.ToString()));
            result.SignatureBase = signatureBase.ToString();

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Generates a signature using the specified signatureType 
        /// </summary>		
        /// <param name="oauth">The information that needs to be signed</param>
        /// <param name="extraParameters">The parameters</param>
        public SignatureResult GenerateSignature(OAuthInfomation oauth, QueryParameterList extraParameters)
        {
            SignatureResult result = new SignatureResult();

            switch (oauth.SignatureMethod)
            {
                case SignatureTypes.PLAINTEXT:
                    result.Signature = HttpUtility.UrlEncode(oauth.GetSignatureKey);
                    break;
                case SignatureTypes.HMACSHA1:
                    result = GenerateSignatureBase(oauth, extraParameters);
                    result.Signature = ComputeHash(new HMACSHA1(Encoding.ASCII.GetBytes(oauth.GetSignatureKey)), result.SignatureBase);
                    break;
                case SignatureTypes.RSASHA1:
                    throw new NotImplementedException();
                default:
                    throw new ArgumentException("Unknown signature type", "signatureType");
            }

            return result;
        }
예제 #3
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="oauth">The information that needs to be signed</param>
        /// <param name="extraParameters">The parameters</param>
        public SignatureResult GenerateSignature(OAuthInfomation oauth, QueryParameterList extraParameters)
        {
            SignatureResult result = new SignatureResult();

            switch (oauth.SignatureMethod)
            {
            case SignatureTypes.PLAINTEXT:
                result.Signature = HttpUtility.UrlEncode(oauth.GetSignatureKey);
                break;

            case SignatureTypes.HMACSHA1:
                result           = GenerateSignatureBase(oauth, extraParameters);
                result.Signature = ComputeHash(new HMACSHA1(Encoding.ASCII.GetBytes(oauth.GetSignatureKey)), result.SignatureBase);
                break;

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();

            default:
                throw new ArgumentException("Unknown signature type", "signatureType");
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Generate the signature base that is used to produce the signature
        /// </summary>
        /// <param name="oauth">The full url that needs to be signed </param>
        /// <param name="extraParameters">The parameters</param>
        private SignatureResult GenerateSignatureBase(OAuthInfomation oauth, QueryParameterList extraParameters)
        {
            if (oauth.Token == null)
            {
                oauth.Token = String.Empty;
            }

            if (oauth.TokenSecret == null)
            {
                oauth.TokenSecret = String.Empty;
            }

            var result = new SignatureResult();

            var parameters = GetQueryParameters(oauth.RequestUri.Query);
            parameters.AddRange(oauth.GetParametersForSignature());
            parameters.AddRange(extraParameters.Where(p => p.NeedSign));
            parameters.Sort(new QueryParameterComparer());

            var signatureBase = new StringBuilder();
            signatureBase.AppendFormat("{0}&", oauth.HttpMethod.ToUpper());
            signatureBase.AppendFormat("{0}&", UrlEncode(oauth.RequestUri.Normalize()));
            signatureBase.AppendFormat("{0}", UrlEncode(parameters.ToString()));
            result.SignatureBase = signatureBase.ToString();

            return result;
        }