Skip to main content

Apex authorization library for services

Project description

apexauthlib

Private Python library for integrating backend services with the company auth-service.

This library provides:

  • Entities used across services (user, service, client, service metadata, permissions).
  • A FastAPI router (auth_api) with login endpoints and dependency helpers that inject the current user + metadata from JWT.
  • A small HTTP client wrapper (AuthApiProvider / AuthApi) for services to:
    • obtain a token (password login or OAuth code exchange),
    • fetch current user and service-scoped metadata,
    • list users for a service,
    • and register/update service permissions.

Notes

  • This documentation is best used along with the documentation for auth-service.
  • This is a private library. If you change it, you should push to GitHub and then update downstream usage by running make install wherever it’s consumed (per team workflow).

Concepts at a glance

Users

The User entity includes:

  • hashed_password: must never expose an actual password through APIs (except in create/update requests handled elsewhere).
  • is_admin: indicates whether the user is a “superadmin”.

Service-scoped auth model

The auth model used by services is service-centric:

  • Services have a name (service_name) and service admins.
  • Each service can define permissions (schema) and per-user metadata values that should align with those permissions.

See: docs/concepts.md


Usage pattern (high-level)

1) Create an AuthApiProvider

Example (from service code):

provider = AuthApiProvider[HaccpPermissions](
    http=FluentHttp(
        Httpx.Builder().with_url(AUTH_SERVICE_API).build(),
    ),
    service_name=SERVICE_NAME,
    formatter=DataclassFormatter(HaccpPermissions),
)

2) Register permissions (service schema)

Example:

provider.for_token(
    provider.login(ADMIN_USERNAME, ADMIN_PASSWORD)
).update_permissions(
    [
        ServicePermission(
            # ...
        )
    ]
)

3) Add FastAPI auth routes + dependencies

Example:

FastApiBuilder()
.with_title(TITLE)
.with_description(DESCRIPTION)
.with_version(VERSION)
.with_route(auth_api)
.with_dependency(
    auth=provider,
    auth_code=AuthCodeApi(
        http=FluentHttp(
            Httpx.Builder()
            .with_url(AUTH_SERVICE_API)
            .build(),
        ),
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
    ),
)
.build()

See: docs/fastapi.md

Known Limitations

Permission sync is name-based only

AuthApi.update_permissions() compares permissions by name and only creates/deletes. If a permission keeps the same name but changes type, default, label, etc., it currently won’t be updated automatically.

Admin password dependency for permission registration

The example uses provider.login(ADMIN_USERNAME, ADMIN_PASSWORD) to obtain a token for updating permissions. If the admin password changes, downstream services must update their configuration, or a more proper flow should be introduced (e.g., service-to-service auth or code-based admin auth).

Refresh tokens are not currently handled in this library

Current flow assumes a bearer access token is provided/used. Supporting refresh tokens would enable longer-lived sessions with automatic token renewal.

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

apexauthlib-0.1.11.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

apexauthlib-0.1.11-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file apexauthlib-0.1.11.tar.gz.

File metadata

  • Download URL: apexauthlib-0.1.11.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for apexauthlib-0.1.11.tar.gz
Algorithm Hash digest
SHA256 3d38d977dbab009b7b2718dc2e5cdc05348affb58458112a783e85c6cbdbebe8
MD5 eb20e156260e2a7d13134db751478cb1
BLAKE2b-256 2443b740c6bc2e70715c2c3c7e8c8948da0094409990d31a36c3142f98b5b130

See more details on using hashes here.

File details

Details for the file apexauthlib-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: apexauthlib-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for apexauthlib-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 1e5f3dc5d65e3bbd88252f90ab14a171884b32f99c5c18d73030b8a2e82a8883
MD5 385991fbd408c12aa48d9db8eed1c491
BLAKE2b-256 9acde0d80ac29603a7ace6b282d24f90c4e1648bb8564f14713dfa53da9c8cfa

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