tfse-admin-api-v0.2/common/security/APIAuth.py

23 lines
518 B
Python
Raw Normal View History

2022-01-11 11:02:46 +08:00
import functools
from flask import request
# 接口密钥
API_SECRET = "EZgo9ykxrYuBMYnYmmKIh"
def api_secret(func):
"""
校验接口请求密钥
"""
@functools.wraps(func)
def internal(*args, **kwargs):
try:
token = request.headers.get('secret')
if token != API_SECRET:
return {"info": "接口密钥错误"}, 401
except Exception:
return {"info": "请求异常"}, 401
return func(*args, **kwargs)
return internal