Python requests session for microsoft with support for oauth2, adal and msal
Project description
Python Requests session for authenticating with Microsoft (MSAL/ADAL)
About
requests_ms_auth
is a Requests compatible session class that you can use to authenticate with Microsoft either over Azure Active Directory Authentication Library (ADAL) or Microsoft Authentication Library (MSAL).
Basic operation
1. Import the class:
# Import the session class
from requests_ms_auth import MsRequestsSession:
2. Prepare credentials
# Prepare your credentials in a dict
auth_config = {
# The Azure resource ID
resource: "12345678-1234-1234-1234-123456789abc"
# The Azure tenant ID
tenant: "12345678-1234-1234-1234-123456789abc"
# The Azure authority host URL
authority_host_url: "https://login.microsoftonline.com"
# The service client ID
client_id: "12345678-1234-1234-1234-123456789abc"
# The service secret
client_secret: "this is a very secret secret key"
# (Optional) An endpoint that should return 200 on get with these credentials (for quickly verifying that auth works)
verification_url: "https://your.service.example.com/your/api/path"
}
3. Instanciate a session from the class:
# Instanciate the class with authentication dict as parameters
session = MsRequestsSession(auth_config)
4. Use the session:
# Use the session as you would use any other Requests session
res = session.get( "https://your.service.example.com/your/api/path")
5. Profit!
The session should automatically fetch a token on startup and when the token expires. It will also verify itself using the optional verification_url if specified, allowing you to terminate early on failure.
License
Please see LICENSE file for details. requests_adal_auth has G-Faps and is licensed under GNU AFFERO GENERAL PUBLIC LICENSE.
History
This project grew from the need of the latigo project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for requests_ms_auth-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd2af5deed83cecbcb173e6af31e487f4baa38538f91bf0e8917101f1365cc20 |
|
MD5 | 4c618ff96746c4ec9270d43f6022838e |
|
BLAKE2b-256 | 7b220537d87b7f01b0933fd6a36a3ba592d581b60386851fbaf4b2ca370fa665 |