This is a library project for the authentication using the basic auth and oidc
Project description
ZMP Authentication Provider
A Python library for authentication using Basic Auth and OIDC (OpenID Connect).
Description
This library provides authentication functionality using both Basic Authentication and OpenID Connect protocols. It's designed to be flexible and easy to integrate into your Python applications.
Installation
pip install zmp-authentication-provider
Requirements
- Python >= 3.12, < 4.0
Dependencies
- pydantic >= 2.10.6
- pydantic-settings >= 2.9.1, < 3.0.0
- fastapi >= 0.115.11, < 0.116.0
- python-dotenv >= 1.0.1, < 2.0.0
- pyjwt >= 2.10.1, < 3.0.0
- requests >= 2.32.3, < 3.0.0
- cryptography >= 42.0.0, < 45.0
- pymongo >= 4.12.0, < 5.0.0
- motor >= 3.7.0, < 4.0.0
Usage
# FastAPI main.py
from zmp_authentication_provider.routes.auth import router as auth_router
from zmp_authentication_provider.service.auth_service import AuthService
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Lifespan for the FastAPI app."""
try:
# 8. Initialize AIOps Service
app.state.aiops_service = AIOpsService.initialize(database=database)
logger.info("AIOps Service initialized")
yield
finally:
...
app = FastAPI(
# root_path=f"{application_settings.root_path}",
title=f"{application_settings.title}",
description=f"{application_settings.description}",
version=f"{application_settings.version}",
docs_url=f"{application_settings.docs_url}",
openapi_url=f"{application_settings.openapi_url}",
redoc_url=f"{application_settings.redoc_url}",
default_response_class=JSONResponse,
debug=True,
# servers=server,
root_path_in_servers=True,
lifespan=lifespan,
)
app.include_router(auth_router, tags=["auth"], prefix=application_settings.root_path)
# router.py
from zmp_authentication_provider.auth.oauth2_keycloak import (
TokenData,
get_current_user,
)
@router.put(
"/jobs/{job_id}",
summary="Update job details",
description="Update the details of an existing job. Only the provided fields will be updated.",
response_description="The updated job information.",
response_class=JSONResponse,
response_model=Job,
response_model_by_alias=False,
response_model_exclude_none=False,
)
async def update_job(
job_update_request: JobUpdateRequest,
job_id: str = Path(..., description="The ID of the job to update"),
service: AIOpsService = Depends(_get_aiops_service),
oauth_user: TokenData = Depends(get_current_user),
):
"""Update a job's information."""
job = Job(
id=job_id,
updated_by=oauth_user.username,
**job_update_request.model_dump(exclude_unset=True),
)
return await service.modify_job(job=job)
Environment Configuration
Put the below value into the.env file in your project root:
# Authentication default configuration
AUTH_HTTP_CLIENT_SSL_VERIFY="True"
AUTH_APPLICATION_ENDPOINT="${AIOPS_API_ENDPOINT}"
# Keycloak configuration
KEYCLOAK_SERVER_URL="https://keycloak.ags.cloudzcp.net/auth"
KEYCLOAK_REALM="ags"
KEYCLOAK_CLIENT_ID="zmp-client"
KEYCLOAK_CLIENT_SECRET="p4W697V2t9WXSh3kCnCfSCt4MHK4myYG"
KEYCLOAK_REDIRECT_URI="${AUTH_APPLICATION_ENDPOINT}/oauth2/callback"
KEYCLOAK_ALGORITHM="RS256"
Development
Development Dependencies
pip install pytest pytest-cov pytest-watcher pytest-asyncio certifi ruff
Quality Tools
pip install pre-commit
Project Structure
The main package is located in the src/zmp_authentication_provider directory.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the terms of the license included in the repository.
Author
- Kilsoo Kang (kilsoo75@gmail.com)
Links
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 zmp_authentication_provider-0.1.27.tar.gz.
File metadata
- Download URL: zmp_authentication_provider-0.1.27.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bee00d7d6cdd8d403fb66469d970451ab9f1cb18009eee6715ccdf3183f8cd6
|
|
| MD5 |
3159f3430cc4d28d8704e782549da5d1
|
|
| BLAKE2b-256 |
fbd16f22d2dbd8ac18442b6e12aa87688aca1761be0853c1eaf6c8234aa39436
|
File details
Details for the file zmp_authentication_provider-0.1.27-py3-none-any.whl.
File metadata
- Download URL: zmp_authentication_provider-0.1.27-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
341e0313b846867368230e3d3d9898617b26a191a3e568e021a2d4fa179160c9
|
|
| MD5 |
89d4e3ad71eb63f0a7a597378682bf80
|
|
| BLAKE2b-256 |
df973d008c4d3f5dee181e3647e73a7c0dacacedc0d3ecadb84c7a17ca1884c9
|