AutoRpa/rpa_oms/app/auth.py

19 lines
722 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 订单中心调本方的共享密钥鉴权。
#
# 内网一对一:请求头 X-Oms-Token,和环境变量 OMS_INBOUND_TOKEN 做 compare_digest。
# 不上 OAuth、不加用户会话。未配置 token 或请求没带 token 一律失败,避免空串把鉴权打成敞开。
# 失败由 main._post_inbound 回 401「身份认证失败」并写审计(token 打码)。
from __future__ import annotations
import os
import secrets
# 比较请求头与环境变量里的共享密钥。两边有空就失败。
def token_ok(provided: str | None) -> bool:
expected = os.getenv("OMS_INBOUND_TOKEN", "")
if not expected or not provided:
return False
return secrets.compare_digest(provided, expected)