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.0.1b1.tar.gz (41.3 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.0.1b1-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for azauthlib-1.0.1b1.tar.gz
Algorithm Hash digest
SHA256 dce1a0db3a6d43512259e4526157b1cab882f49883a6cf6994d333c1dbb6f84c
MD5 b79a309719712c81d3b6140fdbc34c2f
BLAKE2b-256 77a050b7a9a737b3bf4bd8d213f1da427c665fade56b91ba3f23b49c3be9522c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: azauthlib-1.0.1b1-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

Hashes for azauthlib-1.0.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb522aa1fc1f537260b0c2056bd52862fb098a3e415c4cb846ab501f72d5d63d
MD5 060ce0fdf17b7ed59a7cd1dad2c10f67
BLAKE2b-256 cbdd397e17494e22c4fcb108ff671a66fd643b278ca466e77f14c09a9ea12529

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