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

36
secnex/app/query.py Normal file
View File

@@ -0,0 +1,36 @@
import typer
from typing import Optional
from rich.console import Console
from rich.table import Table
from rich.prompt import Prompt
import os
import json
import uuid
import base64
import secnex.utils as utils
console = Console()
query_app = typer.Typer()
@query_app.command(name="tables", help="Create query to list all tables")
def create_query_tables():
"""Create query to list all tables"""
q = """SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'public'"""
console.print(f"Query: {q}", style="dim")
return q
@query_app.command(name="new-apikey", help="Create query to create a new API key")
def create_query_new_apikey():
"""Create query to create a new API key"""
secret = utils.generate_secret()
secret_hash = utils.hash_secret(secret)
id = uuid.uuid4()
q = f"""INSERT INTO api_keys (id, key, enabled, created_at, updated_at) VALUES ('{id}', '{secret_hash}', true, NOW(), NOW())"""
console.print(f"Query: {q}", style="dim")
key = base64.b64encode(f"{id}:{secret}".encode()).decode()
console.print(f"Key: {key}", style="dim")
return key