Document CertificateCredential requires an RSA private key #16694
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mypy is warning about
AadClientCertificate.sign()because it uses a private key returned by cryptography'sload_pem_private_key()for signing, and that method returns one of several possible types all of whosesignmethods take different arguments. So those are legitimate warnings, thank you mypy, that call does indeed raise e.g.TypeError: sign() takes 3 positional arguments but 4 were givenwhen a user passes in a non-RSA private key.However, no user should do that because Azure AD expects clients to sign JWT assertions with RS256, which is to say the client's certificate must have an RSA private key and
load_pem_private_key()must have returnedRSAPrivateKey, or the client can't authenticate anyway, even if it could sign an assertion. The crypticTypeErrorwon't lead a user with the wrong cert back onto the right path, so this PR has CertificateCredential instead raiseValueErrorwith a clear message, documents its requirement for an RSA private key, and makes the situation clear to mypy with a cast.