28 lines
774 B
Python
28 lines
774 B
Python
"""
|
|
API Auth Endpunkte
|
|
"""
|
|
from flask import Blueprint, jsonify, g, session
|
|
from cmbnet.auth import login_required
|
|
from cmbnet.db import get_db
|
|
import secrets
|
|
from datetime import datetime, timedelta
|
|
|
|
api_auth_bp = Blueprint('api_auth', __name__)
|
|
|
|
|
|
@api_auth_bp.route('/auth/ws-token', methods=['GET', 'POST'])
|
|
@login_required
|
|
def ws_token(**kwargs):
|
|
"""Erzeugt ein Zugriffstoken für WebSocket-Authentifizierung"""
|
|
db = get_db()
|
|
token = secrets.token_urlsafe(32)
|
|
expires_at = datetime.now() + timedelta(hours=1)
|
|
|
|
db.execute(
|
|
'INSERT INTO ws_tokens (tenant_id, account_id, token, expires_at) VALUES (?, ?, ?, ?)',
|
|
(g.tenant_id, session['account_id'], token, expires_at)
|
|
)
|
|
db.commit()
|
|
|
|
return jsonify({'token': token})
|