| 303 | |
| 304 | |
| 305 | std::string OAuth10Credentials::createSignature(const Poco::Net::HTTPRequest& request, const std::string& uri, const Poco::Net::HTMLForm& params, const std::string& nonce, const std::string& timestamp) const |
| 306 | { |
| 307 | std::map<std::string, std::string> paramsMap; |
| 308 | paramsMap["oauth_version"] = "1.0"; |
| 309 | paramsMap["oauth_consumer_key"] = percentEncode(_consumerKey); |
| 310 | paramsMap["oauth_nonce"] = percentEncode(nonce); |
| 311 | paramsMap["oauth_signature_method"] = "HMAC-SHA1"; |
| 312 | paramsMap["oauth_timestamp"] = timestamp; |
| 313 | if (!_token.empty()) |
| 314 | { |
| 315 | paramsMap["oauth_token"] = percentEncode(_token); |
| 316 | } |
| 317 | if (!_callback.empty()) |
| 318 | { |
| 319 | paramsMap["oauth_callback"] = percentEncode(_callback); |
| 320 | } |
| 321 | for (Poco::Net::HTMLForm::ConstIterator it = params.begin(); it != params.end(); ++it) |
| 322 | { |
| 323 | paramsMap[percentEncode(it->first)] = percentEncode(it->second); |
| 324 | } |
| 325 | |
| 326 | std::string paramsString; |
| 327 | for (std::map<std::string, std::string>::const_iterator it = paramsMap.begin(); it != paramsMap.end(); ++it) |
| 328 | { |
| 329 | if (it != paramsMap.begin()) paramsString += '&'; |
| 330 | paramsString += it->first; |
| 331 | paramsString += "="; |
| 332 | paramsString += it->second; |
| 333 | } |
| 334 | |
| 335 | std::string signatureBase = request.getMethod(); |
| 336 | signatureBase += '&'; |
| 337 | signatureBase += percentEncode(uri); |
| 338 | signatureBase += '&'; |
| 339 | signatureBase += percentEncode(paramsString); |
| 340 | |
| 341 | std::string signingKey; |
| 342 | signingKey += percentEncode(_consumerSecret); |
| 343 | signingKey += '&'; |
| 344 | signingKey += percentEncode(_tokenSecret); |
| 345 | |
| 346 | Poco::HMACEngine<Poco::SHA1Engine> hmacEngine(signingKey); |
| 347 | hmacEngine.update(signatureBase); |
| 348 | Poco::DigestEngine::Digest digest = hmacEngine.digest(); |
| 349 | std::ostringstream digestBase64; |
| 350 | Poco::Base64Encoder base64Encoder(digestBase64); |
| 351 | base64Encoder.write(reinterpret_cast<char*>(&digest[0]), digest.size()); |
| 352 | base64Encoder.close(); |
| 353 | return digestBase64.str(); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | std::string OAuth10Credentials::percentEncode(const std::string& str) |