private void Initialize(OAuthWebQueryInfo info) { Method = info.WebMethod; ParameterHandling = info.ParameterHandling; if (info.FirstUse) { _recalculate = false; } }
private void Initialize(OAuthWebQueryInfo info) { Method = info.WebMethod; ParameterHandling = info.ParameterHandling; if(info.FirstUse) { _recalculate = false; } }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> 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(WebMethod 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, UserAgent = "Hammock", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return(info); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> 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(WebMethod 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, Callback = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? ""), UserAgent = "Hammock", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return(info); }
public OAuthWebQuery(OAuthWebQueryInfo info) : base(info) { Initialize(info); }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> 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(WebMethod 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, Callback = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? ""), UserAgent = "Hammock", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return info; }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(WebMethod 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 var urlParameters = System.Compat.Web.HttpUtility.ParseQueryString(uri.Query); #else var urlParameters = uri.Query.ParseQueryString(); #endif #if !SILVERLIGHT foreach (var parameter in urlParameters.AllKeys) #else foreach (var parameter in urlParameters.Keys) #endif { switch (method) { case WebMethod.Post: parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); // [DC] Make a copy of the parameters so that the signature double-encode isn't used var copy = new WebParameterCollection(); foreach(var parameter in parameters) { copy.Add(new WebPair(parameter.Name, parameter.Value)); } AddAuthParameters(copy, timestamp, nonce); // [DC] Escape parameters at this point; do not escape again if recalculating var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, copy); 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, UserAgent = "Hammock", ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return info; }
/// <summary> /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an /// <see cref="OAuthWebQuery" /> 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(WebMethod 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, UserAgent = "Hammock", TokenSecret = TokenSecret, ConsumerSecret = ConsumerSecret }; return info; }
public WebRequest DelegatedRequest(string url, Format format) { var credentials = ((OAuthCredentials)Credentials); credentials.Version = "1.0"; credentials.CallbackUrl = string.Empty; var request = new RestRequest { Credentials = Credentials, Path = "account/verify_credentials." + ((format == Format.Json) ? "json" : "xml"), Method = WebMethod.Get }; // TODO: cannot intercept BuildEndpoint without having to mock RestClient var restClient = (RestClient)Client; var endpoint = request.BuildEndpoint(restClient); var webReq = (HttpWebRequest)WebRequest.Create(url); webReq.Headers = new WebHeaderCollection(); webReq.Headers["X-Auth-Service-Provider"] = endpoint.ToString(); var x = new OAuthWebQueryInfo(); var query = Credentials.GetQueryFor(endpoint.ToString(), request, x, WebMethod.Get, true); var info = query.Info as OAuthWebQueryInfo; if (info != null) { var xVerifyCredentialsAuthorization = string.Format(AuthorizationTemplate, info.ConsumerKey, info.Token, info.SignatureMethod, info.Signature, info.Timestamp, info.Nonce, info.Version); webReq.Headers["X-Verify-Credentials-Authorization"] = xVerifyCredentialsAuthorization; } return webReq; }
public OAuthWebQuery(OAuthWebQueryInfo info, bool enableTrace) : base(info, enableTrace) { Initialize(info); }
public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(WebMethod 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 && !MonoTouch var urlParameters = ParseQuery(uri.Query); #else var urlParameters = uri.Query.ParseQueryString(); #endif #if !SILVERLIGHT && !MonoTouch foreach (var parameter in urlParameters) #else foreach (var parameter in urlParameters.Keys) #endif { switch (method) { case WebMethod.Post: parameters.Add(new HttpPostParameter(parameter.Key, parameter.Value)); break; default: parameters.Add(parameter.Key, parameter.Value); break; } } var timestamp = OAuthTools.GetTimestamp(); var nonce = OAuthTools.GetNonce(); // [DC] Make a copy of the parameters so that the signature double-encode isn't used var copy = new WebParameterCollection(); foreach (var parameter in parameters) { copy.Add(new WebPair(parameter.Name, parameter.Value)); } AddAuthParameters(copy, timestamp, nonce); // [DC] Escape parameters at this point; do not escape again if recalculating var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, copy); 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, UserAgent = "Hammock", ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return(info); }
public OAuthWebQuery(OAuthWebQueryInfo info, bool enableTrace) : base(info, enableTrace) { Initialize(info); }
public OAuthWebQuery(OAuthWebQueryInfo info) : base(info) { Initialize(info); }