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.0.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.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lks_idprovider_entraid-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0ef9cce33e55af2972071a37b9674820e60e4fd572629712b22cef2bcc086932
MD5 16140c10a72ff815217980a5bbf856a5
BLAKE2b-256 6173ac762b6e10c27172ce00ea7c12bcd26ace505c8f5ebc1081d200e5b755b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lks_idprovider_entraid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a938f0445993718632e8043f157ab989686d83f709078a0a79e592510cc5aecc
MD5 404751d3164725660657902da8aca361
BLAKE2b-256 a1aabfb53824e67172088ce05f58d17618a16865fcac90a977ddf2b244489379

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