@@ -26,12 +26,12 @@ class CertificateCredential(ClientCredentialBase):
26
26
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
27
27
:param str client_id: the service principal's client ID
28
28
:param str certificate_path: path to a PEM-encoded certificate file including the private key. If not provided,
29
- `certificate_bytes ` is required.
29
+ `certificate_data ` is required.
30
30
31
31
:keyword str authority: Authority of an Azure Active Directory endpoint, for example 'login.microsoftonline.com',
32
32
the authority for Azure Public Cloud (which is the default). :class:`~azure.identity.AzureAuthorityHosts`
33
33
defines authorities for other clouds.
34
- :keyword bytes certificate_bytes : the bytes of a certificate in PEM format, including the private key
34
+ :keyword bytes certificate_data : the bytes of a certificate in PEM format, including the private key
35
35
:keyword password: The certificate's password. If a unicode string, it will be encoded as UTF-8. If the certificate
36
36
requires a different encoding, pass appropriately encoded bytes instead.
37
37
:paramtype password: str or bytes
@@ -68,34 +68,34 @@ def extract_cert_chain(pem_bytes):
68
68
return b"" .join (chain .splitlines ())
69
69
70
70
71
- def get_client_credential (certificate_path , password = None , certificate_bytes = None , send_certificate_chain = False , ** _ ):
71
+ def get_client_credential (certificate_path , password = None , certificate_data = None , send_certificate_chain = False , ** _ ):
72
72
# type: (Optional[str], Optional[Union[bytes, str]], Optional[bytes], bool, **Any) -> dict
73
73
"""Load a certificate from a filesystem path or bytes, return it as a dict suitable for msal.ClientApplication"""
74
74
75
75
if certificate_path :
76
76
with open (certificate_path , "rb" ) as f :
77
- certificate_bytes = f .read ()
78
- elif not certificate_bytes :
79
- raise ValueError ('CertificateCredential requires a value for "certificate_path" or "certificate_bytes "' )
77
+ certificate_data = f .read ()
78
+ elif not certificate_data :
79
+ raise ValueError ('CertificateCredential requires a value for "certificate_path" or "certificate_data "' )
80
80
81
81
if isinstance (password , six .text_type ):
82
82
password = password .encode (encoding = "utf-8" )
83
83
84
- private_key = serialization .load_pem_private_key (certificate_bytes , password = password , backend = default_backend ())
84
+ private_key = serialization .load_pem_private_key (certificate_data , password = password , backend = default_backend ())
85
85
if not isinstance (private_key , RSAPrivateKey ):
86
86
raise ValueError ("CertificateCredential requires an RSA private key because it uses RS256 for signing" )
87
87
88
- cert = x509 .load_pem_x509_certificate (certificate_bytes , default_backend ())
88
+ cert = x509 .load_pem_x509_certificate (certificate_data , default_backend ())
89
89
fingerprint = cert .fingerprint (hashes .SHA1 ()) # nosec
90
90
91
- client_credential = {"private_key" : certificate_bytes , "thumbprint" : hexlify (fingerprint ).decode ("utf-8" )}
91
+ client_credential = {"private_key" : certificate_data , "thumbprint" : hexlify (fingerprint ).decode ("utf-8" )}
92
92
if password :
93
93
client_credential ["passphrase" ] = password
94
94
95
95
if send_certificate_chain :
96
96
try :
97
97
# the JWT needs the whole chain but load_pem_x509_certificate deserializes only the signing cert
98
- chain = extract_cert_chain (certificate_bytes )
98
+ chain = extract_cert_chain (certificate_data )
99
99
client_credential ["public_certificate" ] = six .ensure_str (chain )
100
100
except ValueError as ex :
101
101
# we shouldn't land here--cryptography already loaded the cert and would have raised if it were malformed
0 commit comments