/// <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> /// <a href="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 OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(string method, WebParameterCollection parameters) { ValidateClientAuthAccessRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var uri = new Uri(AccessTokenUrl); var timestamp = CreateTimestampFunc(); var nonce = OAuthTools.GetNonce(RandomNumberGenerator); AddXAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters); var signature = OAuthTools.GetSignature(SignatureProvider, SignatureTreatment, signatureBase, ConsumerSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ClientMode = "client_auth", ClientUsername = ClientUsername, ClientPassword = ClientPassword, ConsumerKey = ConsumerKey, SignatureMethod = SignatureProvider.Id, SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", 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> /// <a href="http://oauth.net/core/1.0#anchor9"/> /// <returns></returns> public OAuthWebQueryInfo BuildRequestTokenInfo(string method, WebParameterCollection parameters) { ValidateTokenRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var timestamp = CreateTimestampFunc(); var nonce = OAuthTools.GetNonce(RandomNumberGenerator); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters); var signature = OAuthTools.GetSignature(SignatureProvider, SignatureTreatment, signatureBase, ConsumerSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, SignatureMethod = SignatureProvider.Id, SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Callback = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? string.Empty), 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 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> /// <a href="http://oauth.net/core/1.0#anchor9"/> /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param> public OAuthWebQueryInfo BuildAccessTokenInfo(string method, WebParameterCollection parameters) { ValidateAccessRequestState(); if (parameters == null) { parameters = new WebParameterCollection(); } var uri = new Uri(AccessTokenUrl); var timestamp = CreateTimestampFunc(); 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); }
public 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 = uri.Query.ParseQueryString(); foreach (var parameter in urlParameters.Keys) { switch (method.ToUpperInvariant()) { case "POST": parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); break; default: parameters.Add(parameter, urlParameters[parameter]); break; } } var timestamp = CreateTimestampFunc(); 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 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 = uri.Query.ParseQueryString(); foreach (var parameter in urlParameters.Keys) { parameters.Add(new WebParameter(parameter, urlParameters[parameter], WebParameterType.Query)); } var timestamp = CreateTimestampFunc(); var nonce = OAuthTools.GetNonce(RandomNumberGenerator); AddAuthParameters(parameters, timestamp, nonce); var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters); var signature = OAuthTools.GetSignature( SignatureProvider, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret); var info = new OAuthWebQueryInfo { WebMethod = method, ParameterHandling = ParameterHandling, ConsumerKey = ConsumerKey, Token = Token, SignatureMethod = SignatureProvider.Id, SignatureTreatment = SignatureTreatment, Signature = signature, Timestamp = timestamp, Nonce = nonce, Version = Version ?? "1.0", Callback = CallbackUrl, ConsumerSecret = ConsumerSecret, TokenSecret = TokenSecret }; return(info); }