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

Commit 59a550e

Browse files
authored
Merge pull request #159 from AzureAD/release-1.0.1
ADAL Python 1.0.1
2 parents 321ea03 + 0f5d21c commit 59a550e

File tree

4 files changed

+44
-79
lines changed

4 files changed

+44
-79
lines changed

README.md

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,33 @@
11
# Microsoft Azure Active Directory Authentication Library (ADAL) for Python
22

3-
The ADAL for python library makes it easy for python applications to authenticate to AAD in order to access AAD protected web resources.
3+
`master` branch | `dev` branch | Reference Docs
4+
--------------------|-----------------|---------------
5+
[![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)
46

5-
## Usage
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)
8+
| --- | --- | --- | --- |
69

7-
### Install
810

9-
To support 'service principal' with certificate, ADAL depends on the 'cryptography' package. For smooth installation, some suggestions:
11+
The ADAL for Python library enables python applications to authenticate with Azure AD and get tokens to access Azure AD protected web resources.
1012

11-
* For Windows and macOS
13+
You can learn in detail about ADAL Python functionality and usage documented in the [Wiki](https://github.com/AzureAD/azure-activedirectory-library-for-python/wiki).
1214

13-
Upgrade to the latest pip (8.1.2 as of June 2016) and just do `pip install adal`.
15+
## Installation and Usage
1416

15-
* For Linux
17+
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.
1618

17-
Upgrade to the latest pip (8.1.2 as of June 2016).
18-
19-
You'll need a C compiler, libffi + its development headers, and openssl + its development headers.
20-
Refer to [cryptography installation](https://cryptography.io/en/latest/installation/)
21-
22-
* To install from source:
23-
24-
Upgrade to the latest pip (8.1.2 as of June 2016).
25-
To avoid dealing with compilation errors from cryptography, first run `pip install cryptography` to use statically-linked wheels.
26-
Next, run `python setup.py install`
27-
28-
If you still like to build from source, refer to [cryptography installation](https://cryptography.io/en/latest/installation/).
29-
For more context, start with this [stackoverflow thread](http://stackoverflow.com/questions/22073516/failed-to-install-python-cryptography-package-with-pip-and-setup-py).
30-
31-
### Acquire Token with Client Credentials
32-
33-
In order to use this token acquisition method, you need to configure a service principal. Please follow [this walkthrough](https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/).
34-
35-
Find the `Main logic` part in the [sample](sample/client_credentials_sample.py#L46-L55).
36-
37-
### Acquire Token with client certificate
38-
A service principal is also required.
39-
Find the `Main logic` part in the [sample](sample/certificate_credentials_sample.py#L55-L64).
40-
41-
### Acquire Token with Refresh Token
42-
Find the `Main logic` part in the [sample](sample/refresh_token_sample.py#L47-L69).
43-
44-
### Acquire Token with device code
45-
Find the `Main logic` part in the [sample](sample/device_code_sample.py#L49-L54).
46-
47-
### Acquire Token with authorization code
48-
Find the `Main logic` part in the [sample](sample/website_sample.py#L107-L115) for a complete bare bones web site that makes use of the code below.
49-
50-
## Logging
51-
52-
#### Personal Identifiable Information (PII) & Organizational Identifiable Information (OII)
53-
54-
Starting from ADAL Python 0.5.1, by default, ADAL logging does not capture or log any PII or OII. The library allows app developers to turn this on by configuring the `enable_pii` flag on the AuthenticationContext. By turning on PII or OII, the app takes responsibility for safely handling highly-sensitive data and complying with any regulatory requirements.
19+
## 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.
5521

56-
```python
57-
//PII or OII logging disabled. Default Logger does not capture any PII or OII.
58-
auth_context = AuthenticationContext(...)
22+
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).
5923

60-
//PII or OII logging enabled
61-
auth_context = AuthenticationContext(..., enable_pii=True)
62-
```
24+
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.
6325

64-
## Samples and Documentation
65-
We provide a full suite of [sample applications on GitHub](https://github.com/azure-samples?utf8=%E2%9C%93&q=active-directory&type=&language=) and an [Azure AD developer landing page](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-developers-guide) 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.
26+
## Versions
6627

67-
It is recommended to read the [Auth Scenarios](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios) doc, specifically the [Scenarios section](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#application-types-and-scenarios). For some topics about registering/integrating an app, checkout [this doc](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications). And finally, we have a great topic on the Auth protocols you would be using and how they play with Azure AD in [this doc](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-openid-connect-code).
28+
This library follows [Semantic Versioning](http://semver.org/).
6829

69-
While Python-specific samples will be added into the aforementioned documents as an on-going effort, you can always find [most relevant samples just inside this library repo](https://github.com/AzureAD/azure-activedirectory-library-for-python/tree/dev/sample).
30+
You can find the changes for each version under [Releases](https://github.com/AzureAD/azure-activedirectory-library-for-python/releases).
7031

7132
## Community Help and Support
7233

@@ -80,29 +41,8 @@ If you find a security issue with our libraries or services please report it to
8041

8142
## Contributing
8243

83-
All code is licensed under the MIT license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. You can clone the repo and start contributing now.
44+
All code is licensed under the MIT license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. Please read the [contributing guide](./contributing.md) before starting.
8445

8546
## We Value and Adhere to the Microsoft Open Source Code of Conduct
8647

8748
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
88-
89-
## Quick Start
90-
91-
### Installation
92-
93-
``` $ pip install adal ```
94-
95-
### http tracing/proxy
96-
If you need to bypass self-signed certificates, turn on the environment variable of `ADAL_PYTHON_SSL_NO_VERIFY`
97-
98-
99-
## Note
100-
101-
### Changes on 'client_id' and 'resource' arguments after 0.1.0
102-
The convenient methods in 0.1.0 have been removed, and now your application should provide parameter values to `client_id` and `resource`.
103-
104-
2 Reasons:
105-
106-
* Each adal client should have an Application ID representing a valid application registered in a tenant. The old methods borrowed the client-id of [azure-cli](https://github.com/Azure/azure-xplat-cli), which is never right. It is simple to register your application and get a client id. You can follow [this walkthrough](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications). Do check out if you are new to AAD.
107-
108-
* The old method defaults the `resource` argument to 'https://management.core.windows.net/', now you can just supply this value explictly. Please note, there are lots of different azure resources you can acquire tokens through adal though, for example, the samples in the repository acquire for the 'graph' resource. Because it is not an appropriate assumption to be made at the library level, we removed the old defaults.

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.0.0'
30+
__version__ = '1.0.1'
3131

3232
import logging
3333

adal/authority.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ def _validate_authority_url(self):
7070
if self._url.query:
7171
raise ValueError("The authority url must not have a query string.")
7272

73-
if self._url.path.count('/') > 1:
73+
path_parts = [part for part in self._url.path.split('/') if part]
74+
if len(path_parts) > 1:
7475
raise ValueError("The authority url must be of the format https://login.microsoftonline.com/your_tenant")
76+
elif len(path_parts) == 1:
77+
self._url = urlparse(self._url.geturl().rstrip('/'))
7578

7679
def _parse_authority(self):
7780
self._host = self._url.hostname

tests/test_authority.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ def test_url_extra_path_elements(self):
186186
"https://login.microsoftonline.com/your_tenant"):
187187
context = AuthenticationContext(self.nonHardCodedAuthority + '/extra/path')
188188

189+
@httpretty.activate
190+
def test_url_extra_slashes(self):
191+
util.setup_expected_instance_discovery_request(200,
192+
cp['authorityHosts']['global'],
193+
{
194+
'tenant_discovery_endpoint': 'http://foobar'
195+
},
196+
self.nonHardCodedAuthorizeEndpoint)
197+
198+
authority_url = self.nonHardCodedAuthority + '/' # This should pass for one or more than one slashes
199+
authority = Authority(authority_url, True)
200+
obj = util.create_empty_adal_object()
201+
authority.validate(obj['call_context'])
202+
req = httpretty.last_request()
203+
util.match_standard_request_headers(req)
204+
205+
@httpretty.activate
206+
def test_url_extra_slashes_change_authority_url(self):
207+
authority_url = self.nonHardCodedAuthority + '/' # This should pass for one or more than one slashes
208+
authority = Authority(authority_url, True)
209+
self.assertTrue(authority._url.geturl(), self.nonHardCodedAuthority)
210+
189211

190212
if __name__ == '__main__':
191213
unittest.main()

0 commit comments

Comments
 (0)