public static ConcatenateRequestElements ( string method, string url, |
||
method | string | The request's HTTP method type |
url | string | The request URL |
parameters | The request's parameters | |
Résultat | string |
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="IAuthenticator" /> for the purpose of exchanging a request token /// for an access token authorized by the user at the Service Provider site. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://oauth.net/core/1.0#anchor9"/> /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param> public virtual OAuthWebQueryInfo BuildAccessTokenInfo(string method, WebParameterCollection parameters) { ValidateAccessRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var uri = new Uri(AccessTokenUrl); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters); var signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, Token = Token, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Verifier = Verifier, Callback = CallbackUrl, TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret, }; return(info); }
/// <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); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="IAuthenticator" /> for the purpose of exchanging user credentials /// for an access token authorized by the user at the Service Provider site. /// </summary> /// <param name="method">The HTTP method for the intended request</param> /// <seealso cref="http://tools.ietf.org/html/draft-dehora-farrell-oauth-accesstoken-creds-00#section-4"/> /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param> public virtual OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(string method, WebParameterCollection parameters) { ValidateClientAuthAccessRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var uri = new Uri(AccessTokenUrl); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddXAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters); var signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ClientMode = "client_auth", ClientUsername = ClientUsername, ClientPassword = ClientPassword, ConsumerKey = ConsumerKey, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return(info); }
public virtual OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(string method, WebParameterCollection parameters) { ValidateClientAuthAccessRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } Uri uri = new Uri(AccessTokenUrl); string timestamp = OAuthTools.GetTimestamp(); string nonce = OAuthTools.GetNonce(); AddXAuthParameters(parameters, timestamp, nonce); string signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters); string signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret); OAuthWebQueryInfo oAuthWebQueryInfo = new OAuthWebQueryInfo(); oAuthWebQueryInfo.WebMethod = method; oAuthWebQueryInfo.ParameterHandling = ParameterHandling; oAuthWebQueryInfo.ClientMode = "client_auth"; oAuthWebQueryInfo.ClientUsername = ClientUsername; oAuthWebQueryInfo.ClientPassword = ClientPassword; 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.TokenSecret = TokenSecret; oAuthWebQueryInfo.ConsumerSecret = ConsumerSecret; return(oAuthWebQueryInfo); }
public string BuildProtectedResourceSignature(string method, WebPairCollection parameters, string url) { ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebPairCollection(); } // Include url parameters in query pool var uri = new Uri(url); var urlParameters = HttpUtility.ParseQueryString(uri.Query); foreach (var parameter in urlParameters.AllKeys) { parameters.Add(parameter, urlParameters[parameter]); } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters); return(OAuthTools.GetSignature( SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret )); }
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); }
public OAuthParameters BuildProtectedResourceSignature(string method, WebPairCollection parameters, string url) { ValidateProtectedResourceState(); var allParameters = new WebPairCollection(); allParameters.AddRange(parameters); // Include url parameters in query pool var uri = new Uri(url); var urlParameters = HttpUtility.ParseQueryString(uri.Query); allParameters.AddRange(urlParameters.AllKeys.Select(x => new WebPair(x, urlParameters[x]))); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); var authParameters = GenerateAuthParameters(timestamp, nonce); allParameters.AddRange(authParameters); var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, allParameters); return(new OAuthParameters { Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret), Parameters = authParameters }); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters, string url) { ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebParameterCollection(); } // Include url parameters in query pool var uri = new Uri(url); #if !SILVERLIGHT && !WINDOWS_PHONE var urlParameters = HttpUtility.ParseQueryString(uri.Query); #else var urlParameters = uri.Query.ParseQueryString(); #endif #if !SILVERLIGHT && !WINDOWS_PHONE foreach (var parameter in urlParameters.AllKeys) #else foreach (var parameter in urlParameters.Keys) #endif { switch (method.ToUpperInvariant()) { case "POST": parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters); var signature = OAuthTools.GetSignature( SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret ); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, Token = Token, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Callback = CallbackUrl, ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return(info); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters, string url) { ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebParameterCollection(); } // Include url parameters in query pool... var uri = new Uri(url); var urlParameters = System.Web.HttpUtility.ParseQueryString(uri.Query); //...unless they were already present at some point, such as being added to the request object foreach (var parameter in urlParameters.AllKeys.Where(k => !parameters.Names.Contains(k))) { switch (method.ToUpperInvariant()) { case "POST": parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters); var signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, Token = Token, SignatureMethod = SignatureMethod.ToRequestValue(), SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Callback = CallbackUrl, ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return(info); }
/// <summary> /// Generates an OAuth signature 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> /// <returns></returns> public string BuildRequestTokenInfo(string method, WebPairCollection parameters) { ValidateTokenRequestState(); parameters ??= new WebPairCollection(); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters); return(OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret)); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters, string url) { ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebParameterCollection(); } Uri uri = new Uri(url); NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(uri.Query); string[] allKeys = nameValueCollection.AllKeys; foreach (string name in allKeys) { string text = method.ToUpperInvariant(); if (text != null && text == "POST") { parameters.Add(new HttpPostParameter(name, nameValueCollection[name])); } else { parameters.Add(name, nameValueCollection[name]); } } string timestamp = OAuthTools.GetTimestamp(); string nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); string signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters); string signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret); OAuthWebQueryInfo oAuthWebQueryInfo = new OAuthWebQueryInfo(); oAuthWebQueryInfo.WebMethod = method; oAuthWebQueryInfo.ParameterHandling = ParameterHandling; oAuthWebQueryInfo.ConsumerKey = ConsumerKey; oAuthWebQueryInfo.Token = Token; oAuthWebQueryInfo.SignatureMethod = SignatureMethod.ToRequestValue(); oAuthWebQueryInfo.SignatureTreatment = SignatureTreatment; oAuthWebQueryInfo.Signature = signature; oAuthWebQueryInfo.Timestamp = timestamp; oAuthWebQueryInfo.Nonce = nonce; oAuthWebQueryInfo.Version = (Version ?? "1.0"); oAuthWebQueryInfo.Callback = CallbackUrl; oAuthWebQueryInfo.ConsumerSecret = ConsumerSecret; oAuthWebQueryInfo.TokenSecret = TokenSecret; return(oAuthWebQueryInfo); }
/// <summary> /// Generates an OAuth signature to pass to the /// <see cref="IAuthenticator" /> for the purpose of exchanging a request token /// for an access token authorized by the user at the Service Provider site. /// </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> public string BuildAccessTokenSignature(string method, WebPairCollection parameters) { ValidateAccessRequestState(); parameters ??= new WebPairCollection(); var uri = new Uri(AccessTokenUrl); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters); return(OAuthTools.GetSignature( SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret )); }
/// <summary> /// Generates an OAuth signature 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> /// <returns></returns> public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection parameters) { ValidateTokenRequestState(); var allParameters = new WebPairCollection(); allParameters.AddRange(parameters); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); var authParameters = GenerateAuthParameters(timestamp, nonce); allParameters.AddRange(authParameters); var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, allParameters); return(new OAuthParameters { Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret), Parameters = authParameters }); }
/// <summary> /// Generates an OAuth signature to pass to an /// <see cref="IAuthenticator" /> for the purpose of exchanging user credentials /// for an access token authorized by the user at the Service Provider site. /// </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> public OAuthParameters BuildClientAuthAccessTokenSignature(string method, WebPairCollection parameters) { ValidateClientAuthAccessRequestState(); var allParameters = new WebPairCollection(); allParameters.AddRange(parameters); var uri = new Uri(AccessTokenUrl); var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); var authParameters = GenerateXAuthParameters(timestamp, nonce); allParameters.AddRange(authParameters); var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), allParameters); return(new OAuthParameters { Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret), Parameters = authParameters }); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters, string url) { this.ValidateProtectedResourceState(); if (parameters == null) { parameters = new WebParameterCollection(); } Trace.WriteLine(string.Format("BuildProtectedResourceInfo: URL {0}", url)); foreach (var param in parameters) { Trace.WriteLine(string.Format("BuildProtectedResourceInfo: PARAM {0} = {1}", param.Name, param.Value)); } // Include url parameters in query pool Uri uri = new Uri(url); #if !SILVERLIGHT && !WINDOWS_PHONE NameValueCollection urlParameters = HttpUtility.ParseQueryString(uri.Query); #else IDictionary <string, string> urlParameters = uri.Query.ParseQueryString(); #endif #if !SILVERLIGHT && !WINDOWS_PHONE foreach (string parameter in urlParameters.AllKeys) #else foreach (string parameter in urlParameters.Keys) #endif { switch (method.ToUpperInvariant()) { case "POST": parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } string timestamp = OAuthTools.GetTimestamp(); string nonce = OAuthTools.GetNonce(); this.AddAuthParameters(parameters, timestamp, nonce); string signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters); string signature = OAuthTools.GetSignature(this.SignatureMethod, this.SignatureTreatment, signatureBase, this.ConsumerSecret, this.TokenSecret); OAuthWebQueryInfo info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = this.ParameterHandling, ConsumerKey = this.ConsumerKey, Token = this.Token, SignatureMethod = this.SignatureMethod.ToRequestValue(), SignatureTreatment = this.SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = this.Version ?? "1.0", Callback = this.CallbackUrl, ConsumerSecret = this.ConsumerSecret, TokenSecret = this.TokenSecret }; return(info); }