惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
N
News and Events Feed by Topic
Recent Announcements
Recent Announcements
D
Docker
M
MIT News - Artificial intelligence
L
LangChain Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
博客园_首页
MongoDB | Blog
MongoDB | Blog
美团技术团队
S
Schneier on Security
G
GRAHAM CLULEY
月光博客
月光博客
有赞技术团队
有赞技术团队
Vercel News
Vercel News
Scott Helme
Scott Helme
P
Privacy International News Feed
Last Week in AI
Last Week in AI
Recorded Future
Recorded Future
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
Simon Willison's Weblog
Simon Willison's Weblog
量子位
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Visual Studio Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
罗磊的独立博客
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Security Affairs
Cloudbric
Cloudbric
爱范儿
爱范儿
H
Heimdal Security Blog
PCI Perspectives
PCI Perspectives

博客园 - KLAPT

Gateway 网关 CodeX =>Skills Redis 内存满了怎么处理 SpringBoot 默认配置修改 JWT 续签 Access Token + Refresh Token 双 Token claudeCode 命令 MyBatis 的 Mapper 接口 AI | CC GUI 集成 IDEA 完整教程 在IDEA中使用Claude Code IDEA中使用CodeX MyBatisPlus解决大数据量查询慢问题 idea 中的 claude code Token Dubbo 和 Spring Cloud Gateway的区别 Transactional 注解中propagation 掌握 Spring 框架这 10 个扩展点 SpringBoot 快速实现 api 加密 Spring Boot/Cloud 中 bootstrap.yml 与 application.yml SpringBoot 实现 DOCX 转 PDF 进程、线程、协程 RSA 加密 Java二维码 ntp服务端和客户端 Chronyd与NTP chronyd 作为服务器时钟 chrony sudo命令和su 的区别 java -cp 和 java -jar Maven 项目打包:实现业务代码与第三方依赖分离 达梦数据库创建用户 梦数据库新增大字段报错问题 达梦数据库操作 MySQL UPDATE多表关联更新 达梦数据库 为HTTP POST请求设置请求体 在Java中调用第三方接口并返回第三方页面 Java调用第三方接口的方法 Nginx 之Rewrite 使用详解 linux 命令 Spring Boot项目中集成Spring Security OAuth2和Apache Shiro
微服务Token鉴权设计的几种方案
KLAPT · 2026-05-24 · via 博客园 - KLAPT

<一>Token透传

6d2140ee9c667cee161edc64cd257830

 这种方式通过透传Token使得各微服务都能获取到当前登录人信息,在代码编写上确实可能会方便,但我认为这不是一种很好的设计方式。

原因一:内部API与外部API混合在一起不太好区分。

原因二:内部换句话说:B服务提供API时不因该关心当前是否为登录状态,登录状态应该由路由中的第一个服务校验维护,在调用后续服务时应该显示的传入相关参数。

不透传数据,显示的提供入参

3a324ad9f8926ca2e8028001f1d64fc3

 路由到达的第一个服务已经对Token进行了解析认证并将userId显示的传递给了后续服务,后续服务不需要再对token进行解析认证。

<二>Fegin内部调用方式

Spring Cloud Gateway + Fegin内部调用,集中在Gateway上做统一认证鉴权,鉴权后在请求头中添加鉴权后的信息转发给后续服务,如:userId等

061f76c863a32a811d8fbcc88186b937

 缺点:A服务调用B服务时,B服务需要写一个内部调用的Controller接口A服务才能通过Fegin调用到B服务,增加了代码量(这里的设计方案是内部调用与外部调用Controllway上做统一认证鉴权,鉴权后在请求头中添加鉴权后的信息转发给后续服务,如:userId等。。。优点:与第一种相比不需要额外编写一个Controller接口,只有本地service与远程DubboService的区别,代码更简洁。

缺点:项目技术栈略微增加了复杂度。

99537ed927241210135b56da6f533f07

 <三>Spring Boot Web + Dubbo内部调用方式

b759b31c0b69232fbba575345a69cb4f

<四>常规模式

通过编写通用的鉴权模块,各服务集成该模块。该模块具备以下功能:

  1. JWT Token解析
  2. 权限校验拦截
  3. 缓存(本地缓存\Redis缓存)

这种模式更适合大型项目团队,可能各微服务都由一个项目组负责。各服务维护自己的权限规则(这里指的是权限规则数据,规则是统一的)

d3239268974b7f0d10ed85f819c6b059