Skip to main content

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

Project description

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).

Installation

pip install coreason-identity

Usage

from coreason_identity import IdentityManager, CoreasonIdentityConfig, InvalidTokenError

# 1. Initialize (The Borrowing)
config = CoreasonIdentityConfig(domain="auth.coreason.com", audience="api://coreason")
identity = IdentityManager(config)

# 2. Validate (The Bouncer)
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.")

    # Access extended attributes
    project = user_context.claims.get("project_context")
    print(f"Authorized for project: {project}")

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

# 3. CLI Login (The Device Flow)
# Initiate the flow
flow = identity.start_device_login()
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}")

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

coreason_identity-0.4.2.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

coreason_identity-0.4.2-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file coreason_identity-0.4.2.tar.gz.

File metadata

  • Download URL: coreason_identity-0.4.2.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coreason_identity-0.4.2.tar.gz
Algorithm Hash digest
SHA256 efceb13345994b575b90ecd51d9307508d88c471ee18df1e15e74a6c5dc94ab8
MD5 725e4c709236dbb69fb16a9c67e2af6f
BLAKE2b-256 3328a46f54d9560c811189d545f1fdd8876df55d7bf5b0649b1ce346df128593

See more details on using hashes here.

Provenance

The following attestation bundles were made for coreason_identity-0.4.2.tar.gz:

Publisher: publish.yml on CoReason-AI/coreason-identity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coreason_identity-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for coreason_identity-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cdf141ab9e7d6b789795e5b79f9ac5458dd8ef6f5e8f400fb7570b4254c10499
MD5 c75c059708742f61462bdb300b066d3b
BLAKE2b-256 b864f644548227947ad178b3ab1aa6dae902a19286b961ecb5460c94638afaea

See more details on using hashes here.

Provenance

The following attestation bundles were made for coreason_identity-0.4.2-py3-none-any.whl:

Publisher: publish.yml on CoReason-AI/coreason-identity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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