Skip to main content

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.

Microsoft REST API Release Date Azure Language License PyPI Static Badge OAuth 2.0 Version Azure AD OpenID Connect Azure DevOps Docs Microsoft Graph Code Style

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.

GUI Screenshot


🛠 Option B: Non-GUI Mode

  1. Using Environment Variables (Recommended):
export TENANT_ID="your-tenant-id"
export CLIENT_ID="your-client-id"
export CLIENT_SECRET="your-client-secret"
  1. 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:

  1. Fork the repo.
  2. Create a feature or bugfix branch.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azauthlib-1.3.1b1.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azauthlib-1.3.1b1-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file azauthlib-1.3.1b1.tar.gz.

File metadata

  • Download URL: azauthlib-1.3.1b1.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.5

File hashes

Hashes for azauthlib-1.3.1b1.tar.gz
Algorithm Hash digest
SHA256 40663f3cf99947e155c0a81cabbb84d4a4b7d2814483f98cac14432b7b265425
MD5 4ff4f1546e14e79a39f636c5185c9901
BLAKE2b-256 ae53b1ef2ef32f5d82367c35b455e119d9b883247458d3cb8bc67f052cd0a499

See more details on using hashes here.

File details

Details for the file azauthlib-1.3.1b1-py3-none-any.whl.

File metadata

  • Download URL: azauthlib-1.3.1b1-py3-none-any.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.5

File hashes

Hashes for azauthlib-1.3.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf1dcdae053d5acc4376cf347f011e52c3ca7610fba1350d7ead3276aaeabdee
MD5 a1673f85d564a453dc28e3bd1bc1e5d2
BLAKE2b-256 da745f95aaf605b194185c277d8dbb7d4eec45c2dd34f87d58acc2f3bb4754ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page