UrlEncodeRelaxed() public static method

URL encodes a string based on section 5.1 of the OAuth spec. Namely, percent encoding with [RFC3986], avoiding unreserved characters, upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.
The Uri.EscapeDataString method is supposed to take on RFC 3986 behavior if certain elements are present in a .config file. Even if this actually worked (which in my experiments it doesn't), we can't rely on every host actually having this configuration element present.
public static UrlEncodeRelaxed ( string value ) : string
value string The value to escape.
return string
Exemplo n.º 1
0
        public virtual OAuthWebQueryInfo BuildRequestTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateTokenRequestState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            string timestamp = OAuthTools.GetTimestamp();
            string nonce     = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);
            string            signatureBase     = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters);
            string            signature         = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret);
            OAuthWebQueryInfo oAuthWebQueryInfo = new OAuthWebQueryInfo();

            oAuthWebQueryInfo.WebMethod          = method;
            oAuthWebQueryInfo.ParameterHandling  = ParameterHandling;
            oAuthWebQueryInfo.ConsumerKey        = ConsumerKey;
            oAuthWebQueryInfo.SignatureMethod    = SignatureMethod.ToRequestValue();
            oAuthWebQueryInfo.SignatureTreatment = SignatureTreatment;
            oAuthWebQueryInfo.Signature          = signature;
            oAuthWebQueryInfo.Timestamp          = timestamp;
            oAuthWebQueryInfo.Nonce          = nonce;
            oAuthWebQueryInfo.Version        = (Version ?? "1.0");
            oAuthWebQueryInfo.Callback       = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? "");
            oAuthWebQueryInfo.TokenSecret    = TokenSecret;
            oAuthWebQueryInfo.ConsumerSecret = ConsumerSecret;
            return(oAuthWebQueryInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> for the purpose of requesting an
        /// unauthorized request token.
        /// </summary>
        /// <param name="method">The HTTP method for the intended request</param>
        /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
        /// <seealso cref="http://oauth.net/core/1.0#anchor9"/>
        /// <returns></returns>
        public virtual OAuthWebQueryInfo BuildRequestTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateTokenRequestState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            var timestamp = OAuthTools.GetTimestamp();
            var nonce     = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);
            var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters);
            var signature     = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret);
            var info          = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = ParameterHandling,
                ConsumerKey        = ConsumerKey,
                SignatureMethod    = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce          = nonce,
                Version        = Version ?? "1.0",
                Callback       = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? ""),
                TokenSecret    = TokenSecret,
                ConsumerSecret = ConsumerSecret
            };

            return(info);
        }
Exemplo n.º 3
0
 public WebPair(string name, string value, bool encode = false)
 {
     Name     = name;
     Value    = value;
     WebValue = encode ? OAuthTools.UrlEncodeRelaxed(value ?? "") : value;
     Encode   = encode;
 }