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.2.2.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.2.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for apexauthlib-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ad466993d8f2a8565f1a0b7008403b6c9573f89e4778b8118a7851d28e231c3e
MD5 7494f871b3c4ef6fc27609b1041fe615
BLAKE2b-256 9a2ea215b3901f2ea3bad68163fd295eee9d977a8ee9bfda5d5bde170070fbc2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for apexauthlib-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8150ca7626bed39e67f05d73d463a3ea9ee535431ba5a554acb9296c7034731d
MD5 895544603b1cb771ec6066a12d4ebc1a
BLAKE2b-256 e8ebc733e001b40fb2ca04189c56304c745c2ae2c3c9675a602e99cb88f8662b

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