Skip to content

Commit ad3401c

Browse files
committed
fix
1 parent 19b685a commit ad3401c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,9 @@ public IReadOnlyDictionary<string, string> GetTokenRequestParams()
3838
};
3939
}
4040

41-
private static string ComputeX5tS256KeyId(X509Certificate2 certificate)
42-
{
43-
// Extract the raw bytes of the certificate’s public key.
44-
var publicKey = certificate.GetPublicKey();
45-
46-
// Compute the SHA-256 hash of the public key.
47-
using (var sha256 = SHA256.Create())
48-
{
49-
byte[] hash = sha256.ComputeHash(publicKey);
50-
51-
// Return the hash encoded in Base64 URL format.
52-
return Base64UrlHelpers.Encode(hash);
53-
}
54-
}
55-
5641
public Task FormatResultAsync(AuthenticationResult authenticationResult, CancellationToken cancellationToken = default)
5742
{
43+
FormatResult(authenticationResult);
5844
return Task.CompletedTask;
5945
}
6046

tests/Microsoft.Identity.Test.Unit/PublicApiTests/MtlsPopTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,28 @@ public void Constructor_ValidCertificate()
196196
Assert.AreEqual(Constants.MtlsPoPTokenType, scheme.AccessTokenType);
197197
}
198198

199+
[TestMethod]
200+
public void SchemeSetsCert()
201+
{
202+
var scheme = new MtlsPopAuthenticationOperation(s_testCertificate);
203+
AuthenticationResult ar = new AuthenticationResult();
204+
205+
scheme.FormatResult(ar);
206+
207+
Assert.AreSame(s_testCertificate, ar.BindingCertificate);
208+
}
209+
210+
[TestMethod]
211+
public async Task SchemeSetsCertAsync()
212+
{
213+
var scheme = new MtlsPopAuthenticationOperation(s_testCertificate);
214+
AuthenticationResult ar = new AuthenticationResult();
215+
216+
await scheme.FormatResultAsync(ar).ConfigureAwait(false);
217+
218+
Assert.AreSame(s_testCertificate, ar.BindingCertificate);
219+
}
220+
199221
private static string ComputeExpectedKeyId(X509Certificate2 certificate)
200222
{
201223
// Get the raw public key bytes

0 commit comments

Comments
 (0)