Python Requests for OAuth2 with ADAL / MSAL with auto-renew access token
About
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.
| Description | Example code |
|---|---|
| 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.
Configuration
Session configuration details might be found in the docstring here
Implementation details
-
The library uses
pip-compilewithrequirements.into manage and pin requirements. Requirements for test are maintained in a separatetest_rquirements.in. -
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
Tests
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):
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;
- OR use
.envfile:
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
Run tests
make test
License
Please see LICENSE file for details. requests_ms_auth is licensed under GNU AFFERO GENERAL PUBLIC LICENSE and has G-Faps.
History
This project grew from the needs of the latigo project.
TODOs
- check if MSAL method works;
- cover crucial parts with tests;
- clear Makefile;
- handle TODOs in the code;
- enable mypy for examples dir.
Metadata
Release files for requests-ms-auth 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| requests_ms_auth-0.3.2.tar.gz | 27.6 kB | Without provenance | Details |
Release files / requests_ms_auth-0.3.2.tar.gz
| Download URL | requests_ms_auth-0.3.2.tar.gz |
|---|---|
| Size | 27.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbd5493a51268b756431a1854f9b3cb941636125ea0516d120d0fe1adeaa642c
|
|
BLAKE2b-256 checksum How to use checksums |
ed5eddcd6b39d5cf46f3b4b64712cd0ad0ace1a29cda222709e8c4b52af02cfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
|
Security for requests-ms-auth 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.