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

Commit e3a0d19

Browse files
authored
Merge pull request #208 from AzureAD/release-1.2.2
Release 1.2.2
2 parents 168292a + 199dc31 commit e3a0d19

File tree

10 files changed

+44
-25
lines changed

10 files changed

+44
-25
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
--------------------|-----------------|---------------
55
[![Build Status](https://travis-ci.org/AzureAD/azure-activedirectory-library-for-python.svg?branch=master)](https://travis-ci.org/AzureAD/azure-activedirectory-library-for-python) | [![Build Status](https://travis-ci.org/AzureAD/azure-activedirectory-library-for-python.svg?branch=dev)](https://travis-ci.org/AzureAD/azure-activedirectory-library-for-python) | [![Documentation Status](https://readthedocs.org/projects/adal-python/badge/?version=latest)](https://adal-python.readthedocs.io/en/latest/?badge=latest)
66

7-
|[Getting Started](https://github.com/AzureAD/azure-activedirectory-library-for-python/wiki)| [Docs](https://aka.ms/aaddev)| [Samples](https://github.com/azure-samples?query=active-directory)| [Support](README.md#community-help-and-support)
7+
|[Getting Started](https://github.com/AzureAD/azure-activedirectory-library-for-python/wiki)| [Docs](https://aka.ms/aaddev)| [Python Samples](https://github.com/Azure-Samples?q=active-directory&language=python)| [Support](README.md#community-help-and-support)
88
| --- | --- | --- | --- |
99

1010

@@ -17,27 +17,29 @@ You can learn in detail about ADAL Python functionality and usage documented in
1717
You can find the steps to install and basic usage of the library under [ADAL Basics](https://github.com/AzureAD/azure-activedirectory-library-for-python/wiki/ADAL-basics) page in the Wiki.
1818

1919
## Samples and Documentation
20-
We provide a full suite of [sample applications on GitHub](https://github.com/azure-samples?utf8=%E2%9C%93&q=active-directory&type=&language=) to help you get started with learning the Azure Identity system. This includes tutorials for native clients and web applications. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect and for calling APIs such as the Graph API.
20+
We provide a full suite of [Python sample applications on GitHub](https://github.com/Azure-Samples?q=active-directory&language=python) to help you get started with learning the Azure Identity system. This will include tutorials for native clients and web applications. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect and for calling APIs such as the Graph API.
21+
22+
There are also some [lightweight samples existing inside this repo](https://github.com/AzureAD/azure-activedirectory-library-for-python/tree/dev/sample).
2123

2224
You can find the relevant samples by scenarios listed in this [wiki page for acquiring tokens using ADAL Python](https://github.com/AzureAD/azure-activedirectory-library-for-python/wiki/Acquire-tokens#adal-python-apis-for-corresponding-flows).
2325

2426
The documents on [Auth Scenarios](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#application-types-and-scenarios) and [Auth protocols](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-openid-connect-code) are recommended reading.
2527

2628
## Versions
2729

28-
This library follows [Semantic Versioning](http://semver.org/).
30+
This library follows [Semantic Versioning](https://semver.org/).
2931

3032
You can find the changes for each version under [Releases](https://github.com/AzureAD/azure-activedirectory-library-for-python/releases).
3133

3234
## Community Help and Support
3335

34-
We leverage [Stack Overflow](http://stackoverflow.com/) to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before.
36+
We leverage [Stack Overflow](https://stackoverflow.com/) to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before.
3537

36-
We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: [http://stackoverflow.com/questions/tagged/adal](http://stackoverflow.com/questions/tagged/adal)
38+
We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: [https://stackoverflow.com/questions/tagged/adal](https://stackoverflow.com/questions/tagged/adal)
3739

3840
## Security Reporting
3941

40-
If you find a security issue with our libraries or services please report it to [[email protected]](mailto:[email protected]) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](http://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/en-us/security/dd252948) and subscribing to Security Advisory Alerts.
42+
If you find a security issue with our libraries or services please report it to [[email protected]](mailto:[email protected]) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](https://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/en-us/security/dd252948) and subscribing to Security Advisory Alerts.
4143

4244
## Contributing
4345

adal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# pylint: disable=wrong-import-position
2929

30-
__version__ = '1.2.1'
30+
__version__ = '1.2.2'
3131

3232
import logging
3333

adal/authentication_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def token_func(self):
181181
def acquire_token_with_authorization_code(self, authorization_code,
182182
redirect_uri, resource,
183183
client_id, client_secret=None, code_verifier=None):
184-
'''Gets a token for a given resource via auhtorization code for a
184+
'''Gets a token for a given resource via authorization code for a
185185
server app.
186186
187187
:param str authorization_code: An authorization code returned from a

adal/authority.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ def _validate_authority_url(self):
7878

7979
path_parts = [part for part in self._url.path.split('/') if part]
8080
if (len(path_parts) > 1) and (not self._whitelisted()): #if dsts host, path_parts will be 2
81-
raise ValueError("The authority url must be of the format https://login.microsoftonline.com/your_tenant")
81+
raise ValueError(
82+
"The path of authority_url (also known as tenant) is invalid, "
83+
"it should either be a domain name (e.g. mycompany.onmicrosoft.com) "
84+
"or a tenant GUID id. "
85+
'Your tenant input was "%s" and your entire authority_url was "%s".'
86+
% ('/'.join(path_parts), self._url.geturl()))
8287
elif len(path_parts) == 1:
8388
self._url = urlparse(self._url.geturl().rstrip('/'))
8489

adal/self_signed_jwt.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ def _raise_on_invalid_jwt_signature(encoded_jwt):
6464
if len(segments) < 3 or not segments[2]:
6565
raise AdalError('Failed to sign JWT. This is most likely due to an invalid certificate.')
6666

67+
def _extract_certs(public_cert_content):
68+
# Parses raw public certificate file contents and returns a list of strings
69+
# Usage: headers = {"x5c": extract_certs(open("my_cert.pem").read())}
70+
public_certificates = re.findall(
71+
r'-----BEGIN CERTIFICATE-----(?P<cert_value>[^-]+)-----END CERTIFICATE-----',
72+
public_cert_content, re.I)
73+
if public_certificates:
74+
return [cert.strip() for cert in public_certificates]
75+
# The public cert tags are not found in the input,
76+
# let's make best effort to exclude a private key pem file.
77+
if "PRIVATE KEY" in public_cert_content:
78+
raise ValueError(
79+
"We expect your public key but detect a private key instead")
80+
return [public_cert_content.strip()]
81+
6782
class SelfSignedJwt(object):
6883

6984
NumCharIn128BitHexString = 128/8*2
@@ -82,7 +97,7 @@ def _create_header(self, thumbprint, public_certificate):
8297
x5t = _create_x5t_value(thumbprint)
8398
header = {'typ':'JWT', 'alg':'RS256', 'x5t':x5t}
8499
if public_certificate:
85-
header['x5c'] = public_certificate
100+
header['x5c'] = _extract_certs(public_certificate)
86101
self._log.debug("Creating self signed JWT header. x5t: %(x5t)s, x5c: %(x5c)s",
87102
{"x5t": x5t, "x5c": public_certificate})
88103

adal/token_cache.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def __eq__(self, other):
5252
_string_cmp(self.client_id, other.client_id) and \
5353
_string_cmp(self.user_id, other.user_id)
5454

55+
def __ne__(self, other):
56+
return not self == other
57+
5558
# pylint: disable=protected-access
5659

5760
def _get_cache_key(entry):

adal/token_request.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#------------------------------------------------------------------------------
2727

2828
from base64 import b64encode
29-
import re
3029

3130
from . import constants
3231
from . import log
@@ -257,18 +256,14 @@ def _get_token_username_password_federated(self, username, password):
257256
username, password)
258257
@staticmethod
259258
def _parse_wstrust_version_from_federation_active_authurl(federation_active_authurl):
260-
wstrust2005_regex = r'[/trust]?[2005][/usernamemixed]?'
261-
wstrust13_regex = r'[/trust]?[13][/usernamemixed]?'
262-
263-
if re.search(wstrust2005_regex, federation_active_authurl):
259+
if '/trust/2005/usernamemixed' in federation_active_authurl:
264260
return WSTrustVersion.WSTRUST2005
265-
elif re.search(wstrust13_regex, federation_active_authurl):
261+
if '/trust/13/usernamemixed' in federation_active_authurl:
266262
return WSTrustVersion.WSTRUST13
267-
268263
return WSTrustVersion.UNDEFINED
269264

270265
def get_token_with_username_password(self, username, password):
271-
self._log.info("Acquiring token with username password.")
266+
self._log.debug("Acquiring token with username password.")
272267
self._user_id = username
273268
try:
274269
token = self._find_token_from_cache()
@@ -301,7 +296,7 @@ def get_token_with_username_password(self, username, password):
301296
return token
302297

303298
def get_token_with_client_credentials(self, client_secret):
304-
self._log.info("Getting token with client credentials.")
299+
self._log.debug("Getting token with client credentials.")
305300
try:
306301
token = self._find_token_from_cache()
307302
if token:
@@ -347,7 +342,7 @@ def get_token_with_refresh_token(self, refresh_token, client_secret):
347342
return self._get_token_with_refresh_token(refresh_token, None, client_secret)
348343

349344
def get_token_from_cache_with_refresh(self, user_id):
350-
self._log.info("Getting token from cache with refresh if necessary.")
345+
self._log.debug("Getting token from cache with refresh if necessary.")
351346
self._user_id = user_id
352347
return self._find_token_from_cache()
353348

adal/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_request_options(self, *options):
7474

7575
def log_return_correlation_id(log, operation_message, response):
7676
if response and response.headers and response.headers.get('client-request-id'):
77-
log.info("{} Server returned this correlation_id: {}".format(
77+
log.debug("{} Server returned this correlation_id: {}".format(
7878
operation_message,
7979
response.headers['client-request-id']))
8080

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
requests==2.20.0
2-
PyJWT==1.0.0
2+
PyJWT==1.7.0
33
#need 2.x for Python3 support
44
python-dateutil==2.1.0
55
#1.1.0 is the first that can be installed on windows
6-
cryptography==2.3.0
6+
cryptography==2.3.1
77
#for testing
88
httpretty==0.8.14
99
pylint==1.5.4

tests/test_authority.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ def test_bad_url_has_query(self):
188188

189189
@httpretty.activate
190190
def test_url_extra_path_elements(self):
191-
with six.assertRaisesRegex(self, ValueError, "The authority url must be of the format "+
192-
"https://login.microsoftonline.com/your_tenant"):
191+
with six.assertRaisesRegex(self, ValueError, "tenant"): # Some tenant specific error message
193192
context = AuthenticationContext(self.nonHardCodedAuthority + '/extra/path')
194193

195194
@httpretty.activate

0 commit comments

Comments
 (0)