A Python library simplifying Azure Microsoft Graph authentication. Provides an intuitive interface for acquiring access tokens through interactive login, silent authentication, device code flow, and client credentials flow. Includes utilities for seamless token storage and refresh management.
Project description
🌟 azauthlib 🌟
Your Simplified Authentication Companion for Azure Microsoft Graph
azauthlib
is a Python library that streamlines the authentication process with Azure Microsoft Graph. From interactive logins to client credentials flow, azauthlib
provides an intuitive interface, robust token management, and a GUI for seamless configuration.
🔐 Whether you're building applications that interact with Microsoft Graph APIs or automating workflows, azauthlib
has you covered.
✨ Features ✨
✅ Multiple Authentication Flows
- Silent Authentication
- Interactive Authentication
- Device Code Flow
- Client Credentials
✅ Graphical User Interface (GUI)
- Configure credentials with an easy-to-use GUI.
✅ Token Management
- Automatic refresh for access tokens
- Secure token storage
✅ Flexible Environment Configuration
- Use
.env
files, OS variables, or direct input.
✅ Customizable Permissions
- Specify Microsoft Graph API scopes effortlessly.
🚀 Installation
Install from PyPI
pip install azauthlib
Install from Source
git clone https://github.com/cedricmoorejr/azauthlib.git
cd azauthlib
pip install .
📋 Requirements
- Python 3.7+
msal
portalocker
python-dotenv
Install dependencies manually if needed:
pip install -r requirements.txt
🛠 Getting Started
1️⃣ Prerequisites
-
Register an app in Azure Active Directory via the Azure Portal.
-
Collect the following:
CLIENT_ID
TENANT_ID
- (Optional)
CLIENT_SECRET
-
Assign the appropriate Microsoft Graph API permissions.
2️⃣ Configuration Options
🌐 Option A: GUI Mode
Launch the GUI for intuitive configuration:
python config_app.py
💡 What You Can Do in the GUI:
- Enter credentials (
CLIENT_ID
,TENANT_ID
, etc.).- Choose your authentication method.
- Credentials are saved securely in a
.env
file.
🛠 Option B: Non-GUI Mode
- Using Environment Variables (Recommended):
export TENANT_ID="your-tenant-id"
export CLIENT_ID="your-client-id"
export CLIENT_SECRET="your-client-secret"
- Hardcoding in Code (⚠️ Not Recommended):
from azauthlib import Authentication
auth = Authentication(scopes="Files.ReadWrite.All")
auth.Build.WithEntry(
client_id="your-client-id",
tenant_id="your-tenant-id",
client_secret="your-client-secret"
)
🔑 Authentication Flows
🔒 Silent Authentication
Authenticate using cached tokens.
auth.Silent()
🌐 Interactive Authentication
Prompts user to log in via a browser.
auth.Interactive()
📱 Device Code Flow
Displays a device code for cross-device authentication.
auth.DeviceCodeFlow(webbrowser_enabled=True)
🤝 Client Credentials Flow
Authenticate server-to-server.
auth.ClientCredentials()
💼 Token Management
-
Access Token: Retrieve the active token.
token = auth.access_token
-
Token Expiry: Check token lifetime.
print("Token expires in:", auth.token_expires_in)
-
Automatic Refresh: Tokens are refreshed seamlessly.
📜 Logging
Easily track authentication flow and token operations using Python’s logging
module. Customize as needed!
🤝 Contributing
We welcome contributions! 🚀 Here's how you can help:
- Fork the repo.
- Create a feature or bugfix branch.
- Submit a PR with a detailed description.
📄 License
This project is licensed under the Apache License 2.0. See the LICENSE
file for more details.
ℹ️ Trademarks
- This project references Microsoft trademarks such as Azure and Microsoft Graph. Please ensure compliance with Microsoft’s Trademark Guidelines.
🔗 GitHub Repository
💬 Feedback? Issues? We’d love to hear from you!
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
File details
Details for the file azauthlib-1.0.0b1.tar.gz
.
File metadata
- Download URL: azauthlib-1.0.0b1.tar.gz
- Upload date:
- Size: 41.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7996cab867e72573a3fdb0b2932e8be02d30c4c05803e50bc5fc6099105fbf1c |
|
MD5 | 4cc2dad41eea0792d3ea4a8d99b77989 |
|
BLAKE2b-256 | 5bb9a220eb927173397aecef9699e12054a865b558734e21e17188b4f9e91fe7 |
File details
Details for the file azauthlib-1.0.0b1-py3-none-any.whl
.
File metadata
- Download URL: azauthlib-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 39.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 692f9fdd0b325c0165a41c3cb2c30469c740391f6a2ed617f29e3e60b81564c1 |
|
MD5 | 751db04b458eebc4930bb718eb43df6b |
|
BLAKE2b-256 | 99e50056e5fc22ece74014ea063efcd22299b7a20b49ba062dfc8159d0418c19 |