Skip to main content

Azure Entra ID provider implementation for LKS Identity Provider library

Project description

LKS-idprovider Entra ID

Azure Entra ID (formerly Azure Active Directory) provider implementation for the LKS Identity Provider library.

Overview

This package provides a complete Azure Entra ID implementation of the LKS-idprovider API specification, including:

  • Azure Entra ID Provider: Complete implementation using Microsoft's azure.identity SDK and JWT validation
  • Microsoft Graph Integration: Seamless integration with Microsoft Graph API for user information
  • Client Credentials Support: OAuth2 client credentials flow using azure.identity
  • JWT Validation: Token validation using PyJWT with JWKS
  • Unified Identity Support: Support for both user and client authentication flows
  • Multiple Auth Methods: Support for client secrets, certificates, and managed identities

Status

🚧 Work in Progress - This package is currently under development.

Key Features

  • Azure Identity SDK: Uses Microsoft's official azure.identity library for authentication
  • Automatic Token Management: Token caching and refresh handled by azure.identity
  • JWT Validation: Token validation with JWKS for security
  • Microsoft Graph API: Native integration with Microsoft Graph for user information
  • Multiple Credential Types: Support for client secrets, certificates, and managed identities
  • Async/Await: Full async support for high-performance applications
  • Type Safety: Complete type hints and Pydantic validation
  • FastAPI Integration: Compatible with lks-idprovider-fastapi

Installation

# Basic installation
pip install lks-idprovider-entraid

# With Microsoft Graph SDK support
pip install lks-idprovider-entraid[graph]

# With Redis caching support
pip install lks-idprovider-entraid[redis]

# Full installation with all optional dependencies
pip install lks-idprovider-entraid[all]

Quick Start

Basic Configuration

from lks_idprovider_entraid import EntraIDConfig, EntraIDProvider

# Configure Azure Entra ID provider
config = EntraIDConfig(
    tenant_id="your-tenant-id",  # or "common" for multi-tenant
    client_id="your-client-id",
    client_secret="your-client-secret"
)

provider = EntraIDProvider(config)

Token Validation

# Validate user token
async with provider:
    auth_context = await provider.get_auth_context("eyJ0eXAiOiJKV1Q...")

    print(f"Identity: {auth_context.identity.name}")
    print(f"Type: {auth_context.identity.identity_type}")
    print(f"Roles: {[role.name for role in auth_context.roles]}")

Client Credentials Flow

from lks_idprovider_entraid import EntraIDClientCredentialsProvider

# Create provider
cc_provider = EntraIDClientCredentialsProvider(config)

# Get token (uses azure.identity internally)
token_response = await cc_provider.get_client_credentials_token(
    scopes=["https://graph.microsoft.com/.default"]
)

access_token = token_response["access_token"]

Configuration

Environment Variables

# Azure Entra ID configuration
ENTRAID_TENANT_ID=your-tenant-id
ENTRAID_CLIENT_ID=your-client-id
ENTRAID_CLIENT_SECRET=your-client-secret

# Optional settings
ENTRAID_AUTHORITY_HOST=login.microsoftonline.com
ENTRAID_API_VERSION=v1.0
ENTRAID_TIMEOUT=30
ENTRAID_VERIFY_SSL=true

Advanced Configuration

from lks_idprovider_entraid import EntraIDConfig

config = EntraIDConfig(
    tenant_id="your-tenant-id",
    client_id="your-client-id",
    client_secret="your-client-secret",

    # JWT validation settings
    validate_audience=True,
    validate_issuer=True,
    leeway=30,  # Clock skew tolerance

    # Caching settings
    jwks_cache_ttl=300,
    token_cache_ttl=60,

    # Microsoft Graph settings
    api_version="v1.0",  # or "beta"

    # HTTP client settings
    timeout=30,
    verify_ssl=True
)

Certificate-Based Authentication

config = EntraIDConfig(
    tenant_id="your-tenant-id",
    client_id="your-client-id",
    certificate_path="/path/to/cert.pem",
    certificate_password="cert-password"
)

Managed Identity Authentication

config = EntraIDConfig(
    tenant_id="your-tenant-id",
    client_id="your-client-id",
    use_managed_identity=True  # For Azure resources
)

Project Structure

lks-idprovider-entraid/
├── src/
│   └── lks_idprovider_entraid/
│       ├── __init__.py
│       ├── config.py              # EntraIDConfig
│       ├── provider.py            # EntraIDProvider (TODO)
│       ├── client_credentials_provider.py  # (TODO)
│       ├── utils.py               # (TODO)
│       └── rest/
│           └── entraid_client.py  # (TODO)
└── tests_entraid/
    ├── conftest.py
    ├── test_config.py
    └── ...

Development

Setup Development Environment

# Clone repository
git clone https://github.com/lks-team/lks-idprovider-python.git
cd lks-idprovider-python/lks-idprovider-entraid

# Activate virtual environment (PowerShell)
.\.venv\Scripts\Activate.ps1

# Install dependencies
poetry install --with dev

# Run tests
poetry run pytest tests_entraid/ -v

# Run tests with coverage
poetry run pytest tests_entraid/ --cov=src/lks_idprovider_entraid --cov-report=html

Related Packages

  • lks-idprovider-api: API specification with protocols and models
  • lks-idprovider-keycloak: Keycloak provider implementation
  • lks-idprovider-fastapi: FastAPI integration

Documentation

For detailed documentation, see:

License

Copyright © LKS Next

Contributing

Contributions are welcome! Please read the contributing guidelines before submitting pull requests.

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

lks_idprovider_entraid-0.1.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

lks_idprovider_entraid-0.1.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file lks_idprovider_entraid-0.1.1.tar.gz.

File metadata

  • Download URL: lks_idprovider_entraid-0.1.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.6 Windows/11

File hashes

Hashes for lks_idprovider_entraid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6ccfe11b9899a78cc3d89c4b7d6252623c48b3c7ff439ba6a72d73784409f4dd
MD5 103a00dac662a7f9ba79f7e9d6583182
BLAKE2b-256 776031a4cf25b8b36d4a1457b91446425ca982961939f42b6c8f7c953bf67a58

See more details on using hashes here.

File details

Details for the file lks_idprovider_entraid-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lks_idprovider_entraid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ddcdab7ec3eed290584687dcdf1f04d6a90b7d026ec35ca05517437101d32ac9
MD5 6ae0afed620a6698c69b8d4d4bee584b
BLAKE2b-256 83f3392ab5cef1f7ed9f3d95ba0bee22aa6ed334be389258153a30c03b70c4d3

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