Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 9b58f3c

Browse files
committed
address review feedback
1 parent ce349d8 commit 9b58f3c

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

adal/authentication_context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,22 @@ def token_func(self):
235235
return self._acquire_token(token_func)
236236

237237
def acquire_token_with_client_certificate(self, resource, client_id,
238-
certificate, thumbprint, send_x5c=False):
238+
certificate, thumbprint, public_certificate=None):
239239
'''Gets a token for a given resource via certificate credentials
240240
241241
:param str resource: A URI that identifies the resource for which the
242242
token is valid.
243243
:param str client_id: The OAuth client id of the calling application.
244244
:param str certificate: A PEM encoded certificate private key.
245245
:param str thumbprint: hex encoded thumbprint of the certificate.
246-
:param send_x5c(optional): if True, send the public certificate through 'x5c' JWT header
247-
for subject name and issuer based authentication, which is to support cert auto rolls
246+
:param public_certificate(optional): if not None, it will be sent to the service for subject name
247+
and issuer based authentication, which is to support cert auto rolls. The value must match the
248+
certificate private key parameter.
248249
:returns: dict with several keys, include "accessToken".
249250
'''
250251
def token_func(self):
251252
token_request = TokenRequest(self._call_context, self, client_id, resource)
252-
return token_request.get_token_with_certificate(certificate, thumbprint, send_x5c)
253+
return token_request.get_token_with_certificate(certificate, thumbprint, public_certificate)
253254

254255
return self._acquire_token(token_func)
255256

adal/self_signed_jwt.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,9 @@ def _reduce_thumbprint(self, thumbprint):
118118
self._raise_on_invalid_thumbprint(canonical)
119119
return canonical
120120

121-
def create(self, certificate, thumbprint, send_x5c):
121+
def create(self, certificate, thumbprint, public_certificate):
122122
thumbprint = self._reduce_thumbprint(thumbprint)
123123

124-
public_certificate = None
125-
if send_x5c:
126-
# to avoid pulling in OpenSSL dependency, we do low-tech but safe parsing based on markers
127-
# defined in "<github>/libressl-portable/openbsd/blob/master/src/lib/libcrypto/pem/pem.h"
128-
match = re.search(r'\-+BEGIN CERTIFICATE.+\-+(?P<public>[^-]+)\-+END CERTIFICATE.+\-+',
129-
certificate, re.I)
130-
if not match:
131-
raise AdalError("Error:Invalid Certificate: Marker of '-----BEGIN CERTIFICATE-----' was not found")
132-
public_certificate = match.group('public').strip()
133-
134124
header = self._create_header(thumbprint, public_certificate)
135125
payload = self._create_payload()
136126
return _sign_jwt(header, payload, certificate)

adal/token_request.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,20 @@ def get_token_from_cache_with_refresh(self, user_id):
351351
self._user_id = user_id
352352
return self._find_token_from_cache()
353353

354-
def _create_jwt(self, certificate, thumbprint, send_x5c):
354+
def _create_jwt(self, certificate, thumbprint, public_certificate):
355355

356356
ssj = self._create_self_signed_jwt()
357-
jwt = ssj.create(certificate, thumbprint, send_x5c)
357+
jwt = ssj.create(certificate, thumbprint, public_certificate)
358358

359359
if not jwt:
360360
raise AdalError("Failed to create JWT.")
361361
return jwt
362362

363-
def get_token_with_certificate(self, certificate, thumbprint, send_x5c):
363+
def get_token_with_certificate(self, certificate, thumbprint, public_certificate):
364364

365365
self._log.info("Getting a token via certificate.")
366366

367-
jwt = self._create_jwt(certificate, thumbprint, send_x5c)
367+
jwt = self._create_jwt(certificate, thumbprint, public_certificate)
368368

369369
oauth_parameters = self._create_oauth_parameters(OAUTH2_GRANT_TYPE.CLIENT_CREDENTIALS)
370370
oauth_parameters[OAUTH2_PARAMETERS.CLIENT_ASSERTION_TYPE] = OAUTH2_GRANT_TYPE.JWT_BEARER

tests/test_self_signed_jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _create_jwt(self, cert, thumbprint, encodeError = None):
6969
else:
7070
self_signed_jwt._encode_jwt = mock.MagicMock(return_value = self.expectedJwt)
7171

72-
jwt = ssjwt.create(cert, thumbprint, False)
72+
jwt = ssjwt.create(cert, thumbprint, public_certificate=None)
7373
return jwt
7474

7575
def _create_jwt_and_match_expected_err(self, testCert, thumbprint, encodeError = None):

0 commit comments

Comments
 (0)