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,38 @@
import requests
from typing import Optional
from datetime import datetime#
from secnex.kit.config.config import Config
from secnex.kit.models.user import User
class UserClient:
def __init__(self, config: Config) -> None:
self.config = config
def get_all(self) -> list[User]:
"""Get all users"""
url = f"{self.config.host}/users"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer 1234567890",
}
response = requests.get(url, headers=headers)
result = response.json()
users = result["body"]["users"]
return [User(**u) for u in users]
def add_user_to_tenant(self, tenant_id: str, user_id: str) -> tuple[bool, int]:
"""Add a user to a tenant"""
url = f"{self.config.host}/users/{user_id}/tenant"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer 1234567890",
}
data = {
"tenant": tenant_id,
}
response = requests.put(url, headers=headers, json=data)
success = response.status_code == 200
return success, response.status_code