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),