chore: 修改 XUserIdHandshakeInterceptor 以支持 Bearer 前缀
All checks were successful
test/timeline-server/pipeline/head This commit looks good

This commit is contained in:
2026-02-11 15:11:08 +08:00
parent 482c32a59c
commit 7972fa775a

View File

@@ -20,8 +20,6 @@ import java.util.Map;
@Slf4j
public class XUserIdHandshakeInterceptor implements HandshakeInterceptor {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(XUserIdHandshakeInterceptor.class);
// 从配置中获取JWT密钥
@Value("${jwt.secret:timelineSecretKey}")
private String jwtSecret = "timelineSecretKey";
@@ -75,6 +73,12 @@ public class XUserIdHandshakeInterceptor implements HandshakeInterceptor {
try {
// URL 解码
token = java.net.URLDecoder.decode(token, java.nio.charset.StandardCharsets.UTF_8);
// 移除 Bearer 前缀(如果存在)
if (token.startsWith("Bearer ")) {
token = token.substring(7);
}
Claims claims = JwtUtils.parseToken(token, jwtSecret);
if (claims != null) {
userId = claims.get("userId", String.class);
@@ -123,7 +127,6 @@ public class XUserIdHandshakeInterceptor implements HandshakeInterceptor {
}
}
public static class UserPrincipal implements Principal {
private final String name;