feat(auth): Add OAuth2 authentication

This commit is contained in:
Björn Benouarets
2026-01-27 16:35:46 +01:00
commit 50c85e9b7f
36 changed files with 1599 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import requests
from typing import Optional
from datetime import datetime#
from secnex.kit.config.config import Config
from secnex.kit.models.tenant import Tenant
class TenantClient:
def __init__(self, config: Config) -> None:
self.config = config
def create(self, name: str) -> tuple[Optional[str], int, bool]:
"""Create a new tenant"""
url = f"{self.config.host}/tenants"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer 1234567890",
}
response = requests.post(url, headers=headers, json={"name": name})
result = response.json()
success = False
tenant_id = None
if "id" in result["body"]:
success = True
tenant_id = result["body"]["id"]
return tenant_id, response.status_code, success
def get_all(self) -> list[Tenant]:
"""Get all tenants"""
url = f"{self.config.host}/tenants"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer 1234567890",
}
response = requests.get(url, headers=headers)
result = response.json()
tenants = result["body"]["tenants"]
return [Tenant(**tenant) for tenant in tenants]