import jwt
def token_required(token):
with open('storage/oauth-public.key', 'r') as f:
public_key = f.read()
try:
# 尝试使用当前算法解码 token,同时指定受众
decoded = jwt.decode(token, public_key, algorithms=['RS256'], options={"verify_aud": False})
# print("Decoded JWT:", decoded)
return decoded.get('jti')
except jwt.ExpiredSignatureError:
print("Token 已过期")
return None
except jwt.InvalidTokenError as e:
print(f"无效的 token: {e}")
return None
开始少写了个参数
options={“verify_aud”: False}
导致一直报错 Invalid audience