Metadata-Version: 2.4
Name: swarmauri_auth_idp_keycloak
Version: 0.11.0.dev2
Summary: Keycloak OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity provider implementations for Swarmauri
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: swarmauri,sdk,experimental,identity,oauth2,oauth21,oidc,keycloak,idp
Author: Jacob Stewart
Author-email: jacob@swarmauri.com
Requires-Python: >=3.10,<3.15
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Security :: Cryptography
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: httpx (>=0.27)
Requires-Dist: pyjwt[crypto] (>=2.8)
Requires-Dist: swarmauri_base
Requires-Dist: swarmauri_core
Description-Content-Type: text/markdown

![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)

<p align="center">
    <a href="https://pepy.tech/project/swarmauri_auth_idp_keycloak/">
        <img src="https://static.pepy.tech/badge/swarmauri_auth_idp_keycloak/month" alt="PyPI - Downloads"/></a>
    <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_auth_idp_keycloak/">
        <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_auth_idp_keycloak.svg"/></a>
    <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
        <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
    <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
        <img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_keycloak" alt="PyPI - License"/></a>
    <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
        <img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_keycloak?label=swarmauri_auth_idp_keycloak&color=green" alt="PyPI - swarmauri_auth_idp_keycloak"/></a>
    <a href="https://discord.gg/N4UpBuQv8T">
        <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>

# Swarmauri Auth IDP Keycloak

Keycloak OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity providers packaged for Swarmauri deployments.

## Features

- PKCE-enabled Authorization Code flows that integrate with Keycloak realm issuers.
- Discovery-driven OAuth 2.1/OIDC login that validates ID tokens against realm JWKS.
- UserInfo enrichment for deployments that require normalized profile payloads.
- Retry-aware HTTP integration tuned for Keycloak endpoints.
- ComponentBase-compatible models registered under `swarmauri.auth_idp` entry points.

## Installation

### pip

```bash
pip install swarmauri_auth_idp_keycloak
```

### uv (project)

```bash
uv add swarmauri_auth_idp_keycloak
```

### uv (environment)

```bash
uv pip install swarmauri_auth_idp_keycloak
```

## Usage

```python
import asyncio
from pydantic import SecretBytes, SecretStr
from swarmauri_auth_idp_keycloak import KeycloakOAuth20Login

login = KeycloakOAuth20Login(
    issuer="https://kc.example.com/realms/myrealm",
    client_id="keycloak-client-id",
    client_secret=SecretStr("keycloak-client-secret"),
    redirect_uri="https://app.example.com/callback",
    state_secret=SecretBytes(b"replace-with-random-bytes"),
)

# Optional: preload discovery metadata when running outside your Keycloak instance.
login.discovery_cache = {
    "authorization_endpoint": "https://kc.example.com/realms/myrealm/protocol/openid-connect/auth",
    "token_endpoint": "https://kc.example.com/realms/myrealm/protocol/openid-connect/token",
    "userinfo_endpoint": "https://kc.example.com/realms/myrealm/protocol/openid-connect/userinfo",
}

async def run_flow() -> None:
    auth = await login.auth_url()
    print(auth["url"])
    # Redirect the browser to `auth["url"]`, then capture the callback `code` and `state`.
    # Later, call `login.exchange_and_identity(code, state)` inside your callback handler.

asyncio.run(run_flow())
```

### Workflow Summary

1. Call `auth_url()` and redirect the browser to the returned URL.
2. Persist the `state` and verify it during the callback handler.
3. Exchange the authorization code through `exchange_and_identity()` to obtain tokens and profile metadata.

## Entry Points

- `swarmauri.auth_idp:KeycloakOAuth20Login`
- `swarmauri.auth_idp:KeycloakOAuth21Login`
- `swarmauri.auth_idp:KeycloakOIDC10Login`

## Contributing

To contribute to swarmauri-sdk, review the
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
which cover development workflow, testing, and coding standards.



