public static string Request(HttpMethod httpMethod, Uri uri, List<Parameter> parameters, string consumerKey, string consumerSecret, string token, string tokenSecret, SignatureMethod signatureMethod = SignatureMethod.HMACSHA1) { var timestamp = GenerateTimeStamp(); var nonce = GenerateNonce(timestamp); var headerParameters = parameters != null ? new List<Parameter>(parameters) : new List<Parameter>(); headerParameters.Add(new Parameter(OAuthParameter.ConsumerKey.Value(), consumerKey)); headerParameters.Add(new Parameter(OAuthParameter.SignatureMethod.Value(), signatureMethod.Value())); headerParameters.Add(new Parameter(OAuthParameter.Timestamp.Value(), timestamp)); headerParameters.Add(new Parameter(OAuthParameter.Nonce.Value(), nonce)); headerParameters.Add(new Parameter(OAuthParameter.Version.Value(), OAuthVersion)); headerParameters.Add(new Parameter(OAuthParameter.Token.Value(), token)); string signatureBaseString = GenerateSignatureBaseString(httpMethod, uri, headerParameters); string signature = GenerateSignature(consumerSecret, signatureMethod, signatureBaseString, tokenSecret); string header = GenerateHeader(consumerKey, signatureMethod.Value(), signature, timestamp, nonce, OAuthVersion, null, token); return Utils.Request(httpMethod, uri, parameters, header); }
public static OpenAuthAccessToken GetAccessToken(Uri uri, string consumerKey, string consumerSecret, string token, string tokenSecret, string verifier, SignatureMethod signatureMethod = SignatureMethod.HMACSHA1) { var timestamp = GenerateTimeStamp(); var nonce = GenerateNonce(timestamp); var parameters = ExtractQueryString(uri.Query); parameters.Add(new Parameter(OAuthParameter.ConsumerKey.Value(), consumerKey)); parameters.Add(new Parameter(OAuthParameter.SignatureMethod.Value(), signatureMethod.Value())); parameters.Add(new Parameter(OAuthParameter.Timestamp.Value(), timestamp)); parameters.Add(new Parameter(OAuthParameter.Nonce.Value(), nonce)); parameters.Add(new Parameter(OAuthParameter.Version.Value(), OAuthVersion)); parameters.Add(new Parameter(OAuthParameter.Token.Value(), token)); parameters.Add(new Parameter(OAuthParameter.Verifier.Value(), verifier)); string signatureBaseString = GenerateSignatureBaseString(HttpMethod.Post, uri, parameters); string signature = GenerateSignature(consumerSecret, signatureMethod, signatureBaseString, tokenSecret); string header = GenerateHeader(consumerKey, signatureMethod.Value(), signature, timestamp, nonce, OAuthVersion, null, token, verifier); string response = Utils.Request(HttpMethod.Post, uri, header); NameValueCollection data = HttpUtility.ParseQueryString(response); if (!data.AllKeys.Contains(OAuthParameter.Token.Value()) || !data.AllKeys.Contains(OAuthParameter.TokenSecret.Value())) throw new OpenAuthException { Error = OpenAuthErrorType.MissingKeys }; return new OpenAuthAccessToken { Token = data[OAuthParameter.Token.Value()], TokenSecret = data[OAuthParameter.TokenSecret.Value()] }; }
public static OpenAuthRequestToken GetRequestToken(Uri uri, string consumerKey, string consumerSecret, string callbackUrl, SignatureMethod signatureMethod = SignatureMethod.HMACSHA1) { var urlEncodedCallback = Utils.UrlEncode(callbackUrl); var timestamp = GenerateTimeStamp(); var nonce = GenerateNonce(timestamp); var parameters = new List<Parameter>(); parameters.Add(new Parameter(OAuthParameter.ConsumerKey.Value(), consumerKey)); parameters.Add(new Parameter(OAuthParameter.SignatureMethod.Value(), signatureMethod.Value())); parameters.Add(new Parameter(OAuthParameter.Timestamp.Value(), timestamp)); parameters.Add(new Parameter(OAuthParameter.Nonce.Value(), nonce)); parameters.Add(new Parameter(OAuthParameter.Version.Value(), OAuthVersion)); parameters.Add(new Parameter(OAuthParameter.Callback.Value(), callbackUrl)); string signatureBaseString = GenerateSignatureBaseString(HttpMethod.Post, uri, parameters); string signature = GenerateSignature(consumerSecret, signatureMethod, signatureBaseString); string header = GenerateHeader(consumerKey, signatureMethod.Value(), signature, timestamp, nonce, OAuthVersion, callbackUrl); string response = Utils.Request(HttpMethod.Post, uri, header); NameValueCollection data = HttpUtility.ParseQueryString(response); if (!data.AllKeys.Contains(OAuthParameter.Token.Value()) || !data.AllKeys.Contains(OAuthParameter.TokenSecret.Value()) || !data.AllKeys.Contains(OAuthParameter.CallbackConfirmed.Value())) throw new OpenAuthException { Error = OpenAuthErrorType.MissingKeys }; return new OpenAuthRequestToken { Token = data[OAuthParameter.Token.Value()], TokenSecret = data[OAuthParameter.TokenSecret.Value()] }; }