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

Commit

Permalink
Merge pull request #159 from AzureAD/release-1.0.1
Browse files Browse the repository at this point in the history
ADAL Python 1.0.1
  • Loading branch information
abhidnya13 authored Jun 11, 2018
2 parents 321ea03 + 0f5d21c commit 59a550e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 79 deletions.
94 changes: 17 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,33 @@
# Microsoft Azure Active Directory Authentication Library (ADAL) for Python

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

## Usage
|[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)
| --- | --- | --- | --- |

### Install

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

* For Windows and macOS
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).

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

* For Linux
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.

Upgrade to the latest pip (8.1.2 as of June 2016).

You'll need a C compiler, libffi + its development headers, and openssl + its development headers.
Refer to [cryptography installation](https://cryptography.io/en/latest/installation/)

* To install from source:

Upgrade to the latest pip (8.1.2 as of June 2016).
To avoid dealing with compilation errors from cryptography, first run `pip install cryptography` to use statically-linked wheels.
Next, run `python setup.py install`

If you still like to build from source, refer to [cryptography installation](https://cryptography.io/en/latest/installation/).
For more context, start with this [stackoverflow thread](http://stackoverflow.com/questions/22073516/failed-to-install-python-cryptography-package-with-pip-and-setup-py).

### Acquire Token with Client Credentials

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/).

Find the `Main logic` part in the [sample](sample/client_credentials_sample.py#L46-L55).

### Acquire Token with client certificate
A service principal is also required.
Find the `Main logic` part in the [sample](sample/certificate_credentials_sample.py#L55-L64).

### Acquire Token with Refresh Token
Find the `Main logic` part in the [sample](sample/refresh_token_sample.py#L47-L69).

### Acquire Token with device code
Find the `Main logic` part in the [sample](sample/device_code_sample.py#L49-L54).

### Acquire Token with authorization code
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.

## Logging

#### Personal Identifiable Information (PII) & Organizational Identifiable Information (OII)

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.
## Samples and Documentation
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.

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

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

## Samples and Documentation
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.
## Versions

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).
This library follows [Semantic Versioning](http://semver.org/).

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).
You can find the changes for each version under [Releases](https://github.com/AzureAD/azure-activedirectory-library-for-python/releases).

## Community Help and Support

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

## Contributing

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.
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.

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

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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Quick Start

### Installation

``` $ pip install adal ```

### http tracing/proxy
If you need to bypass self-signed certificates, turn on the environment variable of `ADAL_PYTHON_SSL_NO_VERIFY`


## Note

### Changes on 'client_id' and 'resource' arguments after 0.1.0
The convenient methods in 0.1.0 have been removed, and now your application should provide parameter values to `client_id` and `resource`.

2 Reasons:

* 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.

* 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.
2 changes: 1 addition & 1 deletion adal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# pylint: disable=wrong-import-position

__version__ = '1.0.0'
__version__ = '1.0.1'

import logging

Expand Down
5 changes: 4 additions & 1 deletion adal/authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ def _validate_authority_url(self):
if self._url.query:
raise ValueError("The authority url must not have a query string.")

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

def _parse_authority(self):
self._host = self._url.hostname
Expand Down
22 changes: 22 additions & 0 deletions tests/test_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ def test_url_extra_path_elements(self):
"https://login.microsoftonline.com/your_tenant"):
context = AuthenticationContext(self.nonHardCodedAuthority + '/extra/path')

@httpretty.activate
def test_url_extra_slashes(self):
util.setup_expected_instance_discovery_request(200,
cp['authorityHosts']['global'],
{
'tenant_discovery_endpoint': 'http://foobar'
},
self.nonHardCodedAuthorizeEndpoint)

authority_url = self.nonHardCodedAuthority + '/' # This should pass for one or more than one slashes
authority = Authority(authority_url, True)
obj = util.create_empty_adal_object()
authority.validate(obj['call_context'])
req = httpretty.last_request()
util.match_standard_request_headers(req)

@httpretty.activate
def test_url_extra_slashes_change_authority_url(self):
authority_url = self.nonHardCodedAuthority + '/' # This should pass for one or more than one slashes
authority = Authority(authority_url, True)
self.assertTrue(authority._url.geturl(), self.nonHardCodedAuthority)


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

0 comments on commit 59a550e

Please sign in to comment.