|
3 | 3 | # Licensed under the MIT License.
|
4 | 4 | # ------------------------------------
|
5 | 5 | import abc
|
6 |
| -import binascii |
7 |
| - |
8 |
| -from cryptography import x509 |
9 |
| -from cryptography.hazmat.primitives import hashes, serialization |
10 |
| -from cryptography.hazmat.backends import default_backend |
11 |
| -from msal.oauth2cli import JwtSigner |
12 |
| -import six |
13 | 6 |
|
14 | 7 | try:
|
15 | 8 | ABC = abc.ABC
|
@@ -41,48 +34,3 @@ def __init__(self, tenant_id, client_id, secret, **kwargs): # pylint:disable=un
|
41 | 34 | )
|
42 | 35 | self._form_data = {"client_id": client_id, "client_secret": secret, "grant_type": "client_credentials"}
|
43 | 36 | super(ClientSecretCredentialBase, self).__init__()
|
44 |
| - |
45 |
| - |
46 |
| -class CertificateCredentialBase(ABC): |
47 |
| - """Sans I/O base for certificate credentials""" |
48 |
| - |
49 |
| - def __init__(self, tenant_id, client_id, certificate_path, **kwargs): # pylint:disable=unused-argument |
50 |
| - # type: (str, str, str, **Any) -> None |
51 |
| - if not certificate_path: |
52 |
| - raise ValueError( |
53 |
| - "'certificate_path' must be the path to a PEM file containing an x509 certificate and its private key" |
54 |
| - ) |
55 |
| - |
56 |
| - super(CertificateCredentialBase, self).__init__() |
57 |
| - |
58 |
| - password = kwargs.pop("password", None) |
59 |
| - if isinstance(password, six.text_type): |
60 |
| - password = password.encode(encoding="utf-8") |
61 |
| - |
62 |
| - with open(certificate_path, "rb") as f: |
63 |
| - pem_bytes = f.read() |
64 |
| - |
65 |
| - private_key = serialization.load_pem_private_key(pem_bytes, password=password, backend=default_backend()) |
66 |
| - cert = x509.load_pem_x509_certificate(pem_bytes, default_backend()) |
67 |
| - fingerprint = cert.fingerprint(hashes.SHA1()) #nosec |
68 |
| - |
69 |
| - self._client = self._get_auth_client(tenant_id, **kwargs) |
70 |
| - self._client_id = client_id |
71 |
| - self._signer = JwtSigner(private_key, "RS256", sha1_thumbprint=binascii.hexlify(fingerprint)) |
72 |
| - |
73 |
| - def _get_request_data(self, *scopes): |
74 |
| - assertion = self._signer.sign_assertion(audience=self._client.auth_url, issuer=self._client_id) |
75 |
| - if isinstance(assertion, six.binary_type): |
76 |
| - assertion = assertion.decode("utf-8") |
77 |
| - |
78 |
| - return { |
79 |
| - "client_assertion": assertion, |
80 |
| - "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", |
81 |
| - "client_id": self._client_id, |
82 |
| - "grant_type": "client_credentials", |
83 |
| - "scope": " ".join(scopes), |
84 |
| - } |
85 |
| - |
86 |
| - @abc.abstractmethod |
87 |
| - def _get_auth_client(self, tenant_id, **kwargs): |
88 |
| - pass |
0 commit comments