Skip to content

Commit 2c6a7a5

Browse files
committed
Fixed an issue with the "OAuth" substring being removed from the "oauth_body_hash" values
1 parent c97b8e9 commit 2c6a7a5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Mastercard.Developer.OAuth1Signer.Core/Signers/NetHttpClientSigner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ private async Task SignPrivateAsync(HttpRequestMessage request)
4747
// Generate the header and add it to the request
4848
var methodString = request.Method.ToString();
4949
var header = OAuth.GetAuthorizationHeader(request.RequestUri.AbsoluteUri, methodString, payload, Encoding, ConsumerKey, SigningKey);
50-
request.Headers.Authorization = new AuthenticationHeaderValue("OAuth", header.Replace("OAuth", string.Empty));
50+
var parameter = header.Substring(6, header.Length - 6); // Remove the "OAuth" scheme
51+
request.Headers.Authorization = new AuthenticationHeaderValue("OAuth", parameter);
5152
}
5253
}
5354
}

Mastercard.Developer.OAuth1Signer.Tests/NetCore2/Signers/NetHttpClientSignerTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,24 @@ public void TestSignAsync_ShouldThrowArgumentNullException_WhenNullRequest()
114114
}
115115

116116
#endregion
117+
118+
[TestMethod]
119+
public void TestSign_ShouldNotRemoveOAuthSubstringFromBodyDigests()
120+
{
121+
// GIVEN
122+
var request = new HttpRequestMessage
123+
{
124+
Method = HttpMethod.Post,
125+
RequestUri = new Uri("https://api.mastercard.com/service"),
126+
Content = new StringContent("{ \"uuid\": \"e8b57e13-a771-4d49-9419-4d1168b0a684\" }") // The SHA-256 digest is "ugxcxkGBiQwu5kGnpvKgrbkOAuthLE+qtCXBDeZ/D/I="
127+
};
128+
129+
// WHEN
130+
CreateHttpClientSigner().Sign(request);
131+
132+
// THEN
133+
Assert.AreEqual("OAuth", request.Headers.Authorization.Scheme);
134+
Assert.IsTrue(request.Headers.Authorization.Parameter.Contains("bkOAuthLE"));
135+
}
117136
}
118137
}

0 commit comments

Comments
 (0)