/******************** protected and support methods ***************************************************************************************************************************/ protected virtual OAuthParameters OAuthParametersFactory() { OAuthParameters oparams = new OAuthParameters(); oparams.addParameter(OAUTH_CONSUMER_KEY, ConsumerKey); oparams.addParameter(OAUTH_NONCE, getNonce()); oparams.addParameter(OAUTH_TIMESTAMP, getTimestamp()); oparams.addParameter(OAUTH_SIGNATURE_METHOD, RSA_SHA1); oparams.addParameter(OAUTH_VERSION, ONE_POINT_ZERO); return(oparams); }
/// <summary> /// Generates and signs the signature base string /// </summary> /// <param name="httpsURL"></param> /// <param name="requestMethod"></param> /// <param name="oparams"></param> /// <returns></returns> private string generateAndSignSignature(String httpsURL, String requestMethod, OAuthParameters oparams) { OAuthParameters sbsParams = new OAuthParameters(); sbsParams.putAll(oparams.getBaseParameters()); string realm = null; if (sbsParams.get(REALM) != EMPTY_STRING) { realm = sbsParams.get(REALM); sbsParams.remove(REALM, null); } String baseString; baseString = generateSignatureBaseString(httpsURL, requestMethod, sbsParams); _signatureBaseString = baseString; String signature; signature = sign(baseString, privateKey); oparams.addParameter(OAUTH_SIGNATURE, signature); if (realm != null) { sbsParams.put(REALM, realm); } return(signature); }
/* -------- private Methods ------------------------------------------------------------------------------------------------------------------ */ /// <summary> /// Method to add the Oauth body hash to the OAuthParameters /// </summary> /// <param name="body"></param> /// <param name="oparams"></param> /// <returns></returns> private OAuthParameters setOauthBodyHashParameter(String body, OAuthParameters oparams) { byte[] bodyStringBytes = encoder.GetBytes(body); SHA1 sha = new SHA1CryptoServiceProvider(); string encodedHash = Convert.ToBase64String(sha.ComputeHash(bodyStringBytes)); oparams.addParameter(OAUTH_BODY_HASH, encodedHash); return(oparams); }
/* -------- private Methods ------------------------------------------------------------------------------------------------------------------ */ /// <summary> /// Method to add the Oauth body hash to the OAuthParameters /// </summary> /// <param name="body"></param> /// <param name="oparams"></param> /// <returns></returns> private OAuthParameters setOauthBodyHashParameter(String body, OAuthParameters oparams) { byte[] bodyStringBytes = encoder.GetBytes(body); SHA1 sha = new SHA1CryptoServiceProvider(); string encodedHash = Convert.ToBase64String(sha.ComputeHash(bodyStringBytes)); oparams.addParameter(OAUTH_BODY_HASH, encodedHash); return oparams; }
/// <summary> /// Generates and signs the signature base string /// </summary> /// <param name="httpsURL"></param> /// <param name="requestMethod"></param> /// <param name="oparams"></param> /// <returns></returns> private string generateAndSignSignature(String httpsURL, String requestMethod, OAuthParameters oparams) { OAuthParameters sbsParams = new OAuthParameters(); sbsParams.putAll(oparams.getBaseParameters()); string realm = null; if (sbsParams.get(REALM) != EMPTY_STRING) { realm = sbsParams.get(REALM); sbsParams.remove(REALM, null); } String baseString; baseString = generateSignatureBaseString(httpsURL, requestMethod, sbsParams); _signatureBaseString = baseString; String signature; signature = sign(baseString, privateKey); oparams.addParameter(OAUTH_SIGNATURE, signature); if (realm != null) { sbsParams.put(REALM, realm); } return signature; }
/******************** protected and support methods ***************************************************************************************************************************/ protected virtual OAuthParameters OAuthParametersFactory() { OAuthParameters oparams = new OAuthParameters(); oparams.addParameter(OAUTH_CONSUMER_KEY, ConsumerKey); oparams.addParameter(OAUTH_NONCE, getNonce()); oparams.addParameter(OAUTH_TIMESTAMP, getTimestamp()); oparams.addParameter(OAUTH_SIGNATURE_METHOD, RSA_SHA1); oparams.addParameter(OAUTH_VERSION, ONE_POINT_ZERO); return oparams; }
/* -------- private Methods ------------------------------------------------------------------------------------------------------------------ */ /// <summary> /// Method to add the Oauth body hash to the OAuthParameters /// </summary> /// <param name="body"></param> /// <param name="oparams"></param> /// <returns></returns> private OAuthParameters setOauthBodyHashParameter(string body, OAuthParameters oparams) { byte[] bodyStringBytes = encoder.GetBytes(body); using (var sha = new SHA1CryptoServiceProvider()) { try { string encodedHash = Convert.ToBase64String(sha.ComputeHash(bodyStringBytes)); oparams.addParameter(OAUTH_BODY_HASH, encodedHash); return oparams; } catch (CryptographicException cex) { throw new MCApiRuntimeException(cex.Message, cex); } } }