18 lines
495 B
Python
18 lines
495 B
Python
# coding=UTF-8
|
|
import json
|
|
from flask import request, current_app, Response
|
|
|
|
|
|
def check_api_key():
|
|
api_keys = current_app.config.get("API_KEYS")
|
|
if not api_keys:
|
|
return
|
|
auth = request.authorization
|
|
if not auth or not auth.username in api_keys:
|
|
response = json.dumps(
|
|
{'status': 401, 'message': 'No valid API key provided'})
|
|
return Response(
|
|
response, 401,
|
|
{'WWW-Authenticate': 'Basic realm="Login Required"'}
|
|
)
|