知识卡片
鉴权中间件统一拦截请求
在 API 请求进入路由前用中间件统一提取并验证访问令牌,可防止各端点重复实现时漏检。公开端点应列出明确豁免范围,受保护端点缺少或无效令牌应拒绝。生产环境应默认启用鉴权,关闭只限明确隔离的测试场景。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 11 章《API authorization and authentication》(源文件:_epub-src/OEBPS/Text/11.htm)
- 结论依据:原文把授权校验放在请求中间件、路由之前,并区分公开与受保护端点;其演示将 `AUTH_ON` 默认设为 False,仅解释为本地开发便利,因此生产环境须纠正此默认值。
- 原始内容:Since authorization is needed to validate user access to the service through the API, we implement it in the API middleware.