Python requests session for microsoft with support for oauth2, adal and msal
Python Requests for OAuth2 with ADAL / MSAL with auto-renew access token
This project provides a simple Requests compatible session that you can use to authenticate with Microsoft using he following:
- Azure Active Directory Authentication Library (ADAL)
- Microsoft Authentication Library (MSAL). (not finished, use ADAL instead)
Session renews access token automatically (by default token expires each hour).
The package is available on PyPi.
How to use
Install the package
python3 -m pip install --upgrade requests_ms_auth
Use an example
NOTE: These examples are made for easy access to Equinor specific systems.
NOTE: Before using the example you should first fill the credentials inside the example file.
|Python code to access Metadata API using session directly||metadata_api_example.py|
The session should automatically fetch a token on startup and renew it when the token expires.
Session will also verify itself in the constructor using the optional
verification_url if specified, allowing you to terminate early on failure.
Session configuration details might be found in the docstring here
The library uses
requirements.into manage and pin requirements. Requirements for test are maintained in a separate
The library uses a Makefile to manage building, packaging and uploading of versions, as well as many short-cuts for running tests, compiling requirements and more.
The library is built and tested by github actions.
The package is prepared and uploaded to PyPi by github actions.
The library defaults to ADAL and can be told to use MSAL as an option.
To supply OAuth2 compatability the library depends on
Config env variables
Export following ENV variables (with previously replaced values):
- from shell:
export INTEGRATION_TENANT=tenant export INTEGRATION_CLIENT_ID=id export INTEGRATION_CLIENT_SECRET=secret export INTEGRATION_RESOURCE=resourse export INTEGRATION_AUTHORITY_HOST_URL=authority export INTEGRATION_LIVE_VERIFICATION_URL=verification export INTEGRATION_LIVE_VERIFICATION_ELEMENT=element
- OR add env variables to Pycharm or other IDE (with previously added values):
- OR use
INTEGRATION_TENANT=tenant INTEGRATION_CLIENT_ID=id INTEGRATION_CLIENT_SECRET=secret INTEGRATION_RESOURCE=resourse INTEGRATION_AUTHORITY_HOST_URL=authority INTEGRATION_LIVE_VERIFICATION_URL=verification INTEGRATION_LIVE_VERIFICATION_ELEMENT=element
Please see LICENSE file for details. requests_ms_auth is licensed under GNU AFFERO GENERAL PUBLIC LICENSE and has G-Faps.
This project grew from the needs of the latigo project.
- check if MSAL method works;
- cover crucial parts with tests;
- clear Makefile;
- handle TODOs in the code;
- enable mypy for examples dir.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size requests_ms_auth-0.3.2.tar.gz (27.6 kB)||File type Source||Python version None||Upload date||Hashes View|