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.3.1.tar.gz (6.1 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.3.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apexauthlib-0.3.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.13 Linux/6.17.0-1010-azure

File hashes

Hashes for apexauthlib-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0a2fdd07f2e6c2552cdcbf8454afe0b5af0ee009abb5142639a1636b75aca6db
MD5 23174c5968ca243cd14c07008e552beb
BLAKE2b-256 b34aded84f7b195df9187d69aa6626b001225e31dee5b8dd2913f3ece135a0f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apexauthlib-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.13 Linux/6.17.0-1010-azure

File hashes

Hashes for apexauthlib-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 000c3bc1b583e9aa54de1d9936da0a2eac0e6df6ab0d7d306b6e0240b9d40101
MD5 311be6c1ce109521661cdfc1fbca80dc
BLAKE2b-256 ed2cb5722b94d5ccfe579e623f03663649fc159bf37ef32039c11f851af87c87

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