-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
26 lines (18 loc) · 755 Bytes
/
auth.py
File metadata and controls
26 lines (18 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from flask import request, jsonify
from functools import wraps
from config import Config
def check_auth(username, password):
"""Vérifie les identifiants d'authentification"""
return username == Config.WEBHOOK_USERNAME and password == Config.WEBHOOK_PASSWORD
def authenticate():
"""Renvoie une réponse 401 demandant l'authentification"""
return jsonify({"error": "Authentication required"}), 401
def requires_auth(f):
"""Décorateur pour vérifier l'authentification HTTP Basic"""
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated