Skip to main content

coreason-identity

Decoupled authentication middleware, abstracting OIDC and OAuth2 protocols from the main application.

Organization License Build Status Code Style: Ruff Documentation

Overview

coreason-identity ("The Bouncer") handles all Authentication (AuthN) and Role-Based Access Control (AuthZ) for the CoReason platform. It enforces a strict "Bouncer" philosophy: it checks IDs and checks lists but does not issue IDs.

The package standardizes:

  • Protocol: OIDC (OpenID Connect).
  • Identity Provider: Auth0 or Keycloak.
  • Library: Authlib.

Features

Based on the Product Requirements:

  • OIDCProvider: Fetches and caches JWKS from the OIDC Discovery URL (LRU Cache).
  • TokenValidator: Validates JWT signatures, standard claims (exp, iss, aud), and enforces strict audience checks to prevent "Confused Deputy" attacks.
  • IdentityMapper: Maps IdP claims to a standardized UserContext model, handling project context extraction and group-to-permission mapping.
  • DeviceFlowClient: Implements RFC 8628 OAuth 2.0 Device Authorization Grant for headless CLI authentication.
  • Observability: Emits OpenTelemetry spans and secure logs (PII hashed).
  • Security: DNS-based SSRF protection, strict DoS limits, PII sanitization, and Replay Protection (JTI Cache). See Security Hardening (SOTA).

Installation

pip install coreason-identity

Usage

1. Token Verification (Server-Side)

Use CoreasonVerifierConfig for services that only need to validate tokens (no client credentials required).

from coreason_identity import IdentityManager, CoreasonVerifierConfig, InvalidTokenError
from pydantic import SecretStr

# Initialize (The Bouncer)
config = CoreasonVerifierConfig(
    domain="auth.coreason.com",
    audience="api://coreason",
    pii_salt=SecretStr("super-secret-salt-123"),  # Mandatory: for PII hashing
    http_timeout=5.0,  # Mandatory: fail fast if IdP is slow
    allowed_algorithms=["RS256"],  # Mandatory: algorithm allowlist
    clock_skew_leeway=0            # Optional: defaults to 0 (strict security)
)
identity = IdentityManager(config)

# Validate (The Check)
try:
    # Validate a raw Bearer token
    user_context = identity.validate_token(auth_header="Bearer eyJ...")

    # Access canonical Identity Passport fields
    print(f"User {user_context.user_id} ({user_context.email}) is active.")

    # Check groups for Row-Level Security
    if "admin" in user_context.groups:
        print("Admin access granted.")

except InvalidTokenError:
    # Handle invalid tokens (expired, bad signature, wrong audience, etc.)
    print("Access denied.")

2. Device Flow Login (CLI / Client-Side)

Use CoreasonClientConfig when the application acts as an OIDC Client (needs client_id).

from coreason_identity import IdentityManager, CoreasonClientConfig

# Initialize (The Borrower)
config = CoreasonClientConfig(
    domain="auth.coreason.com",
    audience="api://coreason",
    client_id="my-cli-client-id",  # Mandatory for client operations
    pii_salt=SecretStr("super-secret-salt-123"),
    http_timeout=10.0,
    allowed_algorithms=["RS256"]
)
identity = IdentityManager(config)

# CLI Login (The Device Flow)
# Initiate the flow
flow = identity.start_device_login(scope="openid profile email")
print(f"Go to {flow.verification_uri} and enter {flow.user_code}")

# Poll for tokens
try:
    tokens = identity.await_device_token(flow)
    print("Login successful!")
    print(f"Access Token: {tokens.access_token}")
except Exception as e:
    print(f"Login failed: {e}")

Metadata

Release files for coreason-identity 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coreason-identity 0.9.0
File Size Uploaded
coreason_identity-0.9.0.tar.gz 23.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coreason-identity 0.9.0
File Interpreter ABI Platform
coreason_identity-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.7 kB

Release files / coreason_identity-0.9.0.tar.gz

Download URL coreason_identity-0.9.0.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bae1f4aa4ca3feb7ab5b8de0f4915449212fad61a75cdb1c1fec0038b14aa419
BLAKE2b-256 checksum
How to use checksums
c6a7aa74a74e9716ad6348ddd8ab7b43105fc377f926a33c9afbe0ea6a0de91f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

Release files / coreason_identity-0.9.0-py3-none-any.whl

Download URL coreason_identity-0.9.0-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c94a39d1f4e1e651d88470db66a238e30148f8e837f6a002abd30bf3d2652ef9
BLAKE2b-256 checksum
How to use checksums
aeb75d81b87dd904c652088479d0a7249bbe502a592595a943780b683ee15cdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page