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 installwherever 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apexauthlib-0.2.1.tar.gz.
File metadata
- Download URL: apexauthlib-0.2.1.tar.gz
- Upload date:
- Size: 6.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82249c2e3111f2d9784b5bc06e1ff830d580dffe300d7d29fb95e52a582127b8
|
|
| MD5 |
f3bef35c1c8cfcf9990025458ddce5bc
|
|
| BLAKE2b-256 |
92964cef259c33763424c675b3d542a96e2ff95b9a2c14aaf44b7806251a7904
|
File details
Details for the file apexauthlib-0.2.1-py3-none-any.whl.
File metadata
- Download URL: apexauthlib-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71e4d9032bdd36ccb0f55cffced5cf2c9881547f7af56d9afedb3dbf52a9d7df
|
|
| MD5 |
98f4ce443f4054a76a9d7ecf4c6b0113
|
|
| BLAKE2b-256 |
89b7d3acf6be185ba54d6ac03dbfd7f1be72a9c164c9e58bace2b19f8c0107da
|