Skip to content

Commit a36a566

Browse files
Fix the regression caused by #899 (#904)
Use different stream objects. Resolves: OLPEDGE-2041 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent c1f2ba7 commit a36a566

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -283,42 +283,40 @@ std::string GenerateAuthorizationHeader(
283283
time_t timestamp, std::string nonce) {
284284
const std::string timestamp_str = std::to_string(timestamp);
285285

286-
std::stringstream stream;
286+
std::stringstream query;
287287

288-
stream << kOauthConsumerKey << kParamEquals << credentials.GetKey()
288+
query << kOauthConsumerKey << kParamEquals << credentials.GetKey()
289289
<< kParamAdd << kOauthNonce << kParamEquals << nonce << kParamAdd
290290
<< kOauthSignatureMethod << kParamEquals << kHmac << kParamAdd
291291
<< kOauthTimestamp << kParamEquals << timestamp_str << kParamAdd
292292
<< kOauthVersion << kParamEquals << kVersion;
293293

294-
const auto encoded_query = utils::Url::Encode(stream.str());
294+
const auto encoded_query = utils::Url::Encode(query.str());
295295

296-
stream.clear();
296+
std::stringstream signature_base;
297297

298-
stream << kOauthPost << kParamAdd << utils::Url::Encode(url) << kParamAdd
298+
signature_base << kOauthPost << kParamAdd << utils::Url::Encode(url) << kParamAdd
299299
<< encoded_query;
300300

301-
const auto signature_base = stream.str();
302-
303-
stream.clear();
304-
305301
const std::string encode_key = credentials.GetSecret() + kParamAdd;
306-
auto hmac_result = Crypto::hmac_sha256(encode_key, signature_base);
302+
auto hmac_result = Crypto::hmac_sha256(encode_key, signature_base.str());
307303
auto signature = Base64Encode(hmac_result);
308304

309-
stream << "OAuth " << kOauthConsumerKey << kParamEquals << kParamQuote
310-
<< utils::Url::Encode(credentials.GetKey()) << kParamQuote
311-
<< kParamComma << kOauthNonce << kParamEquals << kParamQuote
312-
<< utils::Url::Encode(nonce) << kParamQuote << kParamComma
313-
<< kOauthSignatureMethod << kParamEquals << kParamQuote << kHmac
314-
<< kParamQuote << kParamComma << kOauthTimestamp << kParamEquals
315-
<< kParamQuote << utils::Url::Encode(timestamp_str) << kParamQuote
316-
<< kParamComma << kOauthVersion << kParamEquals << kParamQuote
317-
<< kVersion << kParamQuote << kParamComma << kOauthSignature
318-
<< kParamEquals << kParamQuote << utils::Url::Encode(signature)
319-
<< kParamQuote;
320-
321-
return stream.str();
305+
std::stringstream authorization;
306+
307+
authorization << "OAuth " << kOauthConsumerKey << kParamEquals << kParamQuote
308+
<< utils::Url::Encode(credentials.GetKey()) << kParamQuote
309+
<< kParamComma << kOauthNonce << kParamEquals << kParamQuote
310+
<< utils::Url::Encode(nonce) << kParamQuote << kParamComma
311+
<< kOauthSignatureMethod << kParamEquals << kParamQuote << kHmac
312+
<< kParamQuote << kParamComma << kOauthTimestamp << kParamEquals
313+
<< kParamQuote << utils::Url::Encode(timestamp_str)
314+
<< kParamQuote << kParamComma << kOauthVersion << kParamEquals
315+
<< kParamQuote << kVersion << kParamQuote << kParamComma
316+
<< kOauthSignature << kParamEquals << kParamQuote
317+
<< utils::Url::Encode(signature) << kParamQuote;
318+
319+
return authorization.str();
322320
}
323321

324322
} // namespace authentication

olp-cpp-sdk-authentication/tests/AuthenticationClientTest.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ TEST(AuthenticationClientTest, GenerateAuthorizationHeader) {
4242
const auto url = "https://auth.server.com";
4343
auto sig = auth::GenerateAuthorizationHeader(credentials, url, 0, "unique");
4444
auto expected_sig =
45-
"oauth_consumer_key=key&oauth_nonce=unique&oauth_signature_method=HMAC-"
46-
"SHA256&oauth_timestamp=0&oauth_version=1.0POST&https%3A%2F%2Fauth."
47-
"server.com&oauth_consumer_key%3Dkey%26oauth_nonce%3Dunique%26oauth_"
48-
"signature_method%3DHMAC-SHA256%26oauth_timestamp%3D0%26oauth_version%"
49-
"3D1.0OAuth "
45+
"OAuth "
5046
"oauth_consumer_key=\"key\",oauth_nonce=\"unique\",oauth_signature_"
5147
"method=\"HMAC-SHA256\",oauth_timestamp=\"0\",oauth_version=\"1.0\","
52-
"oauth_signature=\"ncwRtcqRSM04FIFch8Ay4l7bRmp96lifuHEops4AqEw%3D\"";
48+
"oauth_signature=\"g1pNnGH65Pl%2B%2FoUNm%2BJBAM9%2BjjgmSuknucOiOwFGFQE%"
49+
"3D\"";
5350
EXPECT_EQ(sig, expected_sig);
5451
}

0 commit comments

Comments
 (0)