Keycloak OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity provider implementations for Swarmauri
Project description
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_idpentry points.
Installation
pip
pip install swarmauri_auth_idp_keycloak
uv (project)
uv add swarmauri_auth_idp_keycloak
uv (environment)
uv pip install swarmauri_auth_idp_keycloak
Usage
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
- Call
auth_url()and redirect the browser to the returned URL. - Persist the
stateand verify it during the callback handler. - Exchange the authorization code through
exchange_and_identity()to obtain tokens and profile metadata.
Entry Points
swarmauri.auth_idp:KeycloakOAuth20Loginswarmauri.auth_idp:KeycloakOAuth21Loginswarmauri.auth_idp:KeycloakOIDC10Login
Contributing
To contribute to swarmauri-sdk, review the guidelines for contributing which cover development workflow, testing, and coding standards.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_auth_idp_keycloak-0.2.0.dev5.tar.gz.
File metadata
- Download URL: swarmauri_auth_idp_keycloak-0.2.0.dev5.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9893425afee8ff7874a1a6e36e2358b55d1c08f6749800c645f7496551fc2fe8
|
|
| MD5 |
87e417839d84ace1c4eda15ac00a0d16
|
|
| BLAKE2b-256 |
a9cfa537884366e81c6a69c3e68188a23df6586cfed0acb1d8ccfca80ff18c17
|
File details
Details for the file swarmauri_auth_idp_keycloak-0.2.0.dev5-py3-none-any.whl.
File metadata
- Download URL: swarmauri_auth_idp_keycloak-0.2.0.dev5-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dfa33fb75cc88ef5f8dddfda7bedcd73066c0db391486cc5a96e28ebeddae19
|
|
| MD5 |
d35721316024e4d1d9a3de027463fde0
|
|
| BLAKE2b-256 |
21a88c70068484d2516bce54ca32505cf4e0082cd7f36c732b39dfe9c66fcfa3
|