Hello @Dmytrii Korostylev,
Based on the error message what you are getting The certificate with identifier used to sign the client assertion is not registered on application. [Reason - The key was not found]. Thumbprint of key used by client: 'xxx', usually occurs when you are using thumbprint as is instead of base64 encoding in x5t(in header) while creating a jwt token.
Please run the following PowerShell script to generate a base64 encoded string of your thumbprint:
# Hexadecimal string
$hexString = "<Thumbprint from portal>"
# Convert the hexadecimal string to a byte array
$bytes = for ($i = 0; $i -lt $hexString.Length; $i += 2) {
[Convert]::ToByte($hexString.Substring($i, 2), 16)
}
# Convert the byte array to a Base64 string
$CertificateBase64Hash = [System.Convert]::ToBase64String($bytes)
# Output the result
$CertificateBase64Hash
Save as .ps1 file and run it in powershell as
.\base64.ps1
Now please use this output in x5t value in header and get the token. Use the generated jwt token as client_assertion in your POST request.
Alternatively, you can fix this issue by adding "trustedCertificateSubjects" to the Manifest section of the application registered in "App registrations" section.
"trustedCertificateSubjects": [
{
"authorityId": "00000000-0000-0000-0000-000000000001",
"subjectName": "XXX.XXXXXXXXXXX.aad.XXXXXX.XX" }
]
Below is the Screenshot for your reference.
Here authorityId is fixed, you can find SubjectName value in your certificate. It will be in this format CN=xyz. Here xyz is your SubjectName.
Please refer to the below article for your reference.
I hope this above information provided is helpful. Please feel free to reach out if you have any further questions.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".