Hello @Ofer Leizerovich
I understand that you are experiencing a paradoxical authentication issue with Azure Entra ID External (formerly B2C) where your application is rejected for both certificate and client secret authentication methods.
The errors you're encountering, AADSTS50146 and AADSTS700027, indicate issues with the configuration of your application in Azure Entra ID External.
To Resolve this AADSTS50146 error Review Security Considerations:
Applications that receive tokens rely on claim values that can't be tampered with. When you modify the token contents through claims customization, these assumptions may no longer be correct. Applications must explicitly acknowledge that tokens have been modified to protect themselves from customizations created by malicious actors. Protect from inappropriate customizations in one the following ways:
Without this, Microsoft Entra ID returns an AADSTS50146 error code.
To Resolve this error "AADSTS700027: The certificate with identifier used to sign the client assertion is not registered on application. [Reason - The key was not found.]"
Cause
This is generally caused when the wrong private key is used to sign the client assertion, or when the wrong Public Key Thumbprint is sent to Azure AD.
Scenario 1: Make sure you are using the correct Private Key.
Troubleshooting
How do I verify that a private key matches a certificate? (OpenSSL) To verify that a private key matches its certificate you need to compare the modulus of the certificate against the modulus of the private key.
Pre-requisite: Install OpenSSL https://slproweb.com/products/Win32OpenSSL.html
Run the following command to view the modulus of the certificate.
openssl x509 -noout -modulus -in server.crt | openssl md5
Now you will receive the modulus something like a77c7953ea5283056a0c9ad75b274b96
Run the following command to view the modulus of the private key.
openssl rsa -noout -modulus -in myserver.key | openssl md5
Now you should get the modulus as same as certificate modulus above. i.e. a77c7953ea5283056a0c9ad75b274b96
If the modulus of the certificate and the modulus of the private key do not match, then you're not using the right private key. You can either create a brand-new key.
Scenario 2: Wrong Public Key provided in Client Assertion request
When the Client Assertion is generated, the Public Key to be used is identified in the "kid" or "x5t" claim.
Make sure these claims are updated correctly.
Do let Us know if you have any Queries. we are happy to assist you further.