From bd4350c17f0dbe5a89146a1e197a0b333cf6d481 Mon Sep 17 00:00:00 2001 From: sccsbc Date: Fri, 10 Jul 2026 13:35:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Apple=20=E7=99=BB?= =?UTF-8?q?=E5=BD=95=20sub=20claim=20=E6=98=A0=E5=B0=84=20+=20=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=96=87=E6=A1=88=E4=B8=AD=E6=96=87=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AppleTokenValidator: 从 JwtSecurityToken 原始 Claims 取 sub,避免 .NET ClaimType 映射导致丢失 - 登录页 Apple 按钮改为中文"通过 Apple 登录" Co-Authored-By: Claude --- .../Health.Infrastructure/Services/apple_token_validator.cs | 5 +++-- health_app/lib/pages/auth/login_page.dart | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/Health.Infrastructure/Services/apple_token_validator.cs b/backend/src/Health.Infrastructure/Services/apple_token_validator.cs index 38a420a..8c685ce 100644 --- a/backend/src/Health.Infrastructure/Services/apple_token_validator.cs +++ b/backend/src/Health.Infrastructure/Services/apple_token_validator.cs @@ -49,8 +49,9 @@ public sealed class AppleTokenValidator ClockSkew = TimeSpan.FromMinutes(1), }; - var principal = handler.ValidateToken(identityToken, validationParams, out _); - var sub = principal.FindFirst("sub")?.Value; + handler.ValidateToken(identityToken, validationParams, out _); + // 从原始 JWT 取 sub(避免 .NET 的 ClaimType 映射把 "sub" 转成 NameIdentifier) + var sub = rawToken.Claims.FirstOrDefault(c => c.Type == "sub")?.Value; if (string.IsNullOrWhiteSpace(sub)) throw new SecurityTokenException("Missing 'sub' claim in Apple identityToken"); diff --git a/health_app/lib/pages/auth/login_page.dart b/health_app/lib/pages/auth/login_page.dart index e408710..8c3b90b 100644 --- a/health_app/lib/pages/auth/login_page.dart +++ b/health_app/lib/pages/auth/login_page.dart @@ -563,6 +563,7 @@ class _LoginPageState extends ConsumerState { onPressed: _loading ? () {} : () { _appleSignIn(); }, style: SignInWithAppleButtonStyle.whiteOutlined, height: 48, + text: '通过 Apple 登录', ), ], const SizedBox(height: 16),