Repository navigation
fix: Include scopes with login and remove new token in password reset completion. - #4143
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis pull request refactors authentication identity providers (Apple, Email, Google) to centralize token issuance through a new TokenIssuer abstraction, replacing per-provider session creation logic. Returns types for password reset change to void, and Google authentication utilities convert from concrete classes to record typedefs. Transaction handling becomes standardized through DatabaseUtil methods. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant IDP as Identity Provider<br/>(Apple/Email/Google)
participant Utils as IDPUtils
participant TokenIssuer
participant AuthDB as Auth Database
rect rgb(240, 248, 255)
Note over IDP,TokenIssuer: NEW: Token Issuance Flow
Client->>IDP: login()/authenticate()
IDP->>Utils: authenticate() / process credentials
Utils->>AuthDB: create/fetch AuthUser & Account
AuthDB-->>Utils: AuthUser with scopes
Utils-->>IDP: auth result with scopes
IDP->>TokenIssuer: issueToken(authUserId, scopes, method, transaction)
TokenIssuer->>AuthDB: create AuthSession
AuthDB-->>TokenIssuer: session token
TokenIssuer-->>IDP: AuthSuccess
IDP-->>Client: AuthSuccess (token + metadata)
end
sequenceDiagram
participant EmailClient
participant EmailEndpoint
participant EmailIDP
participant TokenManager
participant AuthDB
rect rgb(255, 240, 245)
Note over EmailEndpoint,AuthDB: Password Reset Flow (Updated)
EmailClient->>EmailEndpoint: finishPasswordReset(resetId, code, newPassword)
EmailEndpoint->>EmailIDP: finishPasswordReset(resetId, code, newPassword)
EmailIDP->>AuthDB: verify reset & update password
EmailIDP->>TokenManager: revokeAllTokens(userId, method)
TokenManager->>AuthDB: delete all sessions
EmailIDP-->>EmailEndpoint: void (no token returned)
EmailEndpoint-->>EmailClient: 200 OK (no session token)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Areas requiring extra attention:
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
- OWASP: Once they have set their new password, the user should then login through the usual mechanism. Don't automatically log the user in, as this introduces additional complexity to the authentication and session handling code, and increases the likelihood of introducing vulnerabilities.
32ddf9d to
25015c6
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart (1)
62-73: Update test description and expectation to match void return.The test description states "it returns auth session token" but
finishPasswordResetnow returnsvoid(per OWASP guidance). The test also expectsAuthSuccessbut the method no longer returns a token.Apply this diff to fix the test:
test( - 'when finishPasswordReset is called with valid parameters then it returns auth session token', + 'when finishPasswordReset is called with valid parameters then it completes successfully', () async { - final result = fixture.emailIDP.finishPasswordReset( + final result = await fixture.emailIDP.finishPasswordReset( session, passwordResetRequestId: passwordResetRequestId, verificationCode: verificationCode, newPassword: allowedNewPassword, ); - await expectLater(result, completion(isA<AuthSuccess>())); });
🧹 Nitpick comments (1)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart (1)
91-95: Ensure AuthUsers.get participates in the active transactionInside
runInTransactionOrSavepointevery ORM call should reuse the providedtransaction. Skipping it here means the lookup runs outside the caller’s transaction/savepoint, which can surface stale scope data or break atomicity when the caller supplies a surrounding transaction. Please pass the handle through for consistency.- false => await AuthUsers.get( - session, - authUserId: googleAccount!.authUserId, - ), + false => await AuthUsers.get( + session, + authUserId: googleAccount!.authUserId, + transaction: transaction, + ),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
examples/auth/auth_client/lib/src/protocol/client.dartis excluded by!**/lib/src/protocol/**modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_client/lib/src/protocol/client.dartis excluded by!**/lib/src/protocol/**tests/serverpod_new_auth_test/serverpod_new_auth_test_client/lib/src/protocol/client.dartis excluded by!**/lib/src/protocol/**
📒 Files selected for processing (14)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dart(5 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart(4 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart(5 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_account_creation_util.dart(2 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart(3 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart(5 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart(3 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_registration_test.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart(3 hunks)tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart(3 hunks)tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart(1 hunks)tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart(4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.dart: Format all Dart code usingdart format .before committing
Code must pass Dart analyzer in strict mode (util/run_tests_analyze or melos lint_strict)
Use descriptive variable and function names
Files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_registration_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_account_creation_util.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
**/*_test.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*_test.dart: Write test descriptions using the Given/When/Then pattern
Organize tests with passing/success cases first, group related cases using group(), then follow with error cases
Files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_registration_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
**/lib/**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Remove unnecessary comments from production code
Files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_account_creation_util.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
🧠 Learnings (18)
📓 Common learnings
Learnt from: tp
Repo: serverpod/serverpod PR: 3787
File: modules/new_serverpod_auth/serverpod_auth_apple_account/serverpod_auth_apple_account_server/lib/src/business/apple_accounts.dart:65-67
Timestamp: 2025-07-15T13:10:16.490Z
Learning: In Serverpod Apple authentication, tp prefers adding a `lastRefreshed` field to the database model to track when refresh tokens were last validated, enabling periodic refresh token validation strategy for Apple Sign-In accounts.
📚 Learning: 2025-08-26T13:22:33.125Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_accounts.dart:0-0
Timestamp: 2025-08-26T13:22:33.125Z
Learning: The passkeys_server Dart library evolved from version 0.3.0 to 0.4.0, adding required parameters to verifyRegistration and verifyLogin methods for complete WebAuthn security validation including challenge, clientDataJSON, and attestationObject verification.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_registration_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-06-18T14:49:11.263Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3672
File: tests/serverpod_test_server/test_integration/test_tools/test_session_builder_test.dart:10-30
Timestamp: 2025-06-18T14:49:11.263Z
Learning: In Serverpod test files, tp prefers using nullable late variables for AuthenticationInfo in tests (e.g., `late AuthenticationInfo? authenticationInfo;`) rather than non-nullable ones to avoid using `!` operators and to get clearer error messages when authentication setup fails. This provides better diagnostics when `session.authenticated` returns null.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-09-17T16:09:20.868Z
Learnt from: nielsenko
Repo: serverpod/serverpod PR: 3980
File: packages/serverpod/lib/src/web_server/web_server.dart:102-115
Timestamp: 2025-09-17T16:09:20.868Z
Learning: In Serverpod's web server authentication handling (packages/serverpod/lib/src/web_server/web_server.dart), query parameter authentication fallback (`authenticationKey ??= queryParameters['auth']`) is intentionally maintained for legacy compatibility reasons, even though it has security implications regarding credential leakage.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-10-15T11:44:29.873Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T11:44:29.873Z
Learning: Applies to **/*_test.dart : Write test descriptions using the Given/When/Then pattern
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart
📚 Learning: 2025-06-16T12:07:26.018Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts.dart:35-39
Timestamp: 2025-06-16T12:07:26.018Z
Learning: The `withServerpod` test helper runs tests within a transaction, which may require adapting database queries to accept transaction parameters for proper snapshot consistency during testing.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart
📚 Learning: 2025-06-17T11:38:13.087Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart:130-143
Timestamp: 2025-06-17T11:38:13.087Z
Learning: In serverpod_auth_email_account EmailAccountsAdmin, tp prefers relying on database unique constraint exceptions over application-level pre-insert checks for email uniqueness, especially in contexts with longer-running transactions where TOCTOU issues could still occur.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart
📚 Learning: 2025-08-25T19:46:58.073Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3917
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/analysis_options.yaml:3-6
Timestamp: 2025-08-25T19:46:58.073Z
Learning: In Serverpod, test tool paths like `test/integration/test_tools/serverpod_test_tools.dart` are configured per project in the "generator.yaml" file and managed by a generator system, so they don't need to be updated manually across all files at once.
Applied to files:
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
📚 Learning: 2025-07-02T16:09:27.702Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml:37-38
Timestamp: 2025-07-02T16:09:27.702Z
Learning: In Serverpod migration testing, it's appropriate for test servers like serverpod_new_auth_test_server to include dependencies on both legacy packages (e.g., serverpod_auth_server) and new modular packages to enable comprehensive testing of migration paths from old to new authentication systems.
Applied to files:
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-07-15T13:38:58.183Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3787
File: modules/new_serverpod_auth/serverpod_auth_apple_account/serverpod_auth_apple_account_server/pubspec.yaml:18-18
Timestamp: 2025-07-15T13:38:58.183Z
Learning: For Sign in with Apple authentication, there are two distinct packages: `sign_in_with_apple` is the client-side package for mobile apps, while `sign_in_with_apple_server` is a server-side utility package for handling Sign in with Apple tokens and validation on Dart servers.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
📚 Learning: 2025-07-02T16:07:50.947Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
📚 Learning: 2025-06-20T12:49:16.373Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/test/integration/auth_migration_email_test.dart:0-0
Timestamp: 2025-06-20T12:49:16.373Z
Learning: In test files, when testing that an async method completes without error (especially when the test name/description mentions "completes without error"), use the pattern `await expectLater(asyncMethodCall(), completes)` instead of just `await asyncMethodCall()`. This makes the test intention explicit and provides better test failure messages. However, don't apply this pattern to setup calls or when testing side effects rather than completion behavior. For tests that check both completion and side effects, consider splitting into separate tests or prioritize the primary assertion.
Applied to files:
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-06-20T12:49:16.373Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/test/integration/auth_migration_email_test.dart:0-0
Timestamp: 2025-06-20T12:49:16.373Z
Learning: In test files, when testing that an async method completes without error (especially when the test name/description mentions "completes without error"), use the pattern `await expectLater(asyncMethodCall(), completes)` instead of just `await asyncMethodCall()`. This makes the test intention explicit and provides better test failure messages. However, don't apply this pattern to setup calls or when testing side effects rather than completion behavior.
Applied to files:
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.darttests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-07-24T13:46:05.689Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3824
File: packages/serverpod/lib/src/authentication/authentication_info.dart:21-34
Timestamp: 2025-07-24T13:46:05.689Z
Learning: In Serverpod's AuthenticationInfo class, the `userId` getter is being kept temporarily for legacy support with packages that use `int` user IDs, but will be removed in a future PR. The `userIdentifier` field now supports UUID strings for new auth modules, representing the planned migration from int-based to UUID-based user identification.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
📚 Learning: 2025-07-15T13:10:16.490Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3787
File: modules/new_serverpod_auth/serverpod_auth_apple_account/serverpod_auth_apple_account_server/lib/src/business/apple_accounts.dart:65-67
Timestamp: 2025-07-15T13:10:16.490Z
Learning: In Serverpod Apple authentication, tp prefers adding a `lastRefreshed` field to the database model to track when refresh tokens were last validated, enabling periodic refresh token validation strategy for Apple Sign-In accounts.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
📚 Learning: 2025-07-16T07:33:13.578Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3788
File: modules/new_serverpod_auth/serverpod_auth_apple/serverpod_auth_apple_server/lib/src/endpoints/apple_account_base_endpoint.dart:32-40
Timestamp: 2025-07-16T07:33:13.578Z
Learning: In Serverpod Apple authentication, the `lastRefreshed` field should only be updated in the `checkAccountStatus` method when the refresh token is actually used and validated, not during sign-in. During sign-in, the system uses the Apple identity token to find users by their Apple-provided user identifier, without checking or validating the refresh token.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dartmodules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
📚 Learning: 2025-07-24T13:01:52.743Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3826
File: modules/new_serverpod_auth/serverpod_auth_apple/serverpod_auth_apple_client/lib/serverpod_auth_apple_client.dart:1-1
Timestamp: 2025-07-24T13:01:52.743Z
Learning: High-level serverpod_auth_* packages (like serverpod_auth_apple_client) should re-export their serverpod_auth_* dependencies so that consumers only need to import the high-level package and don't get warnings about importing from non-dependency packages. The re-exports should hide conflicting elements like 'Caller' and 'Protocol' to avoid naming conflicts. This pattern prevents users from needing to directly depend on multiple internal implementation packages.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
📚 Learning: 2025-08-06T06:58:47.019Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3855
File: modules/new_serverpod_auth/serverpod_auth_apple_account/serverpod_auth_apple_account_server/lib/src/business/apple_accounts.dart:143-159
Timestamp: 2025-08-06T06:58:47.019Z
Learning: The `_siwa.decodeAppleServerNotification` method from the sign_in_with_apple_server package automatically performs signature verification against Apple's published keys, including JWT signature verification and certificate chain validation. This means webhook handlers using this method already have built-in security against spoofed notifications.
Applied to files:
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (40)
- GitHub Check: Migration e2e tests (3.29.0)
- GitHub Check: Bootstrap tests (3.35.2, windows-latest, tests/bootstrap_project)
- GitHub Check: Migration e2e tests (3.35.2)
- GitHub Check: CLI e2e tests (3.29.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: CLI e2e tests (3.35.2, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: Bootstrap tests (3.35.2, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: Bootstrap tests (3.29.0, windows-latest, tests/bootstrap_project)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.35.2
- GitHub Check: Serverpod concurrent integration tests (server) (3.35.2)
- GitHub Check: Serverpod integration tests (server) (3.29.0)
- GitHub Check: Bootstrap tests (3.29.0, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: Serverpod integration tests (flutter)
- GitHub Check: Serverpod integration tests (server) (3.35.2)
- GitHub Check: Serverpod concurrent integration tests (server) (3.29.0)
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.35.2
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.29.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server with Flutter 3.29.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.29.0
- GitHub Check: dart analyze downgrade (3.29.0, windows-latest)
- GitHub Check: dart analyze downgrade (3.29.0, ubuntu-latest)
- GitHub Check: dart analyze downgrade (3.35.2, windows-latest)
- GitHub Check: dart analyze downgrade (3.35.2, ubuntu-latest)
- GitHub Check: serverpod generate (3.29.0)
- GitHub Check: serverpod generate (3.35.2)
- GitHub Check: Serverpod E2E web tests (3.35.2)
- GitHub Check: Serverpod E2E web tests (3.29.0)
- GitHub Check: Unit tests Web (3.29.0, windows-latest)
- GitHub Check: Unit tests Web (3.35.2, windows-latest)
- GitHub Check: Serverpod E2E IO tests (3.29.0)
- GitHub Check: Flutter unit tests (3.35.2, windows-latest, packages/serverpod_flutter)
- GitHub Check: Flutter unit tests (3.29.0, windows-latest, packages/serverpod_flutter)
- GitHub Check: Serverpod E2E IO tests (3.35.2)
- GitHub Check: Unit tests IO (3.35.2, windows-latest)
- GitHub Check: Unit tests IO (3.35.2, ubuntu-latest)
- GitHub Check: Unit tests IO (3.29.0, windows-latest)
- GitHub Check: dart analyze latest (3.35.2, ubuntu-latest)
- GitHub Check: dart analyze (3.29.0, windows-latest)
- GitHub Check: dart analyze (3.29.0, ubuntu-latest)
- GitHub Check: Unit tests IO (3.29.0, ubuntu-latest)
- GitHub Check: dart analyze latest (3.35.2, windows-latest)
🔇 Additional comments (19)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_account_creation_util.dart (2)
164-169: LGTM! Scopes properly propagated from new user.The addition of scopes to
EmailIDPCompleteAccountCreationResultcorrectly captures the scopes from the newly createdAuthUserand aligns with the PR's objective to ensure scopes are included in authentication flows.
611-627: LGTM! Scopes field properly added to result class.The
scopesfield is correctly documented, declared as a required field, and initialized in the constructor. This ensures that account creation results consistently carry the associated user scopes.modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart (2)
350-352: Good use of public constant for token method.Using
EmailIDP.methodinstead of the literal string'email'improves maintainability and consistency across the codebase.
371-389: LGTM! Test correctly validates session destruction.The test properly verifies that
finishPasswordResetcompletes and that all existing sessions are destroyed, which aligns with the security best practice of requiring re-authentication after password reset.modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_registration_test.dart (1)
90-94: LGTM! Good test for default scope behavior.This test properly validates that newly registered users have no scopes by default, ensuring the baseline security posture is correct.
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart (2)
721-754: LGTM! Auto-generated test endpoint correctly reflects API changes.The
finishPasswordResetsignature has been properly updated to returnFuture<void>and accept the requirednewPasswordparameter, aligning with the PR's OWASP-compliant changes.
1015-1048: LGTM! Consistent signature update across endpoints.The password importing email account endpoint's
finishPasswordResethas been updated consistently with the same signature changes.modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart (2)
12-31: LGTM! Test setup properly configures scopes.The test group description accurately reflects the scoped setup, and the
AuthUsers.updatecall correctly assigns test scopes to validate scope propagation through the login flow.
78-90: LGTM! Good test coverage for scope propagation.This test properly validates that scopes assigned to a user are correctly included in the
AuthSuccessreturned from login, ensuring the PR's objective of including scopes in authentication flows is met.tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart (1)
189-205: LGTM! Test correctly updated for void return.The test description and assertions have been properly updated to validate completion rather than token issuance, aligning with the OWASP-recommended pattern of requiring login after password reset. The use of
expectLater(passwordReset, completes)follows the preferred test pattern per coding guidelines.tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart (2)
530-542: LGTM! Test correctly validates completion behavior.The test has been properly updated to validate that
finishPasswordResetcompletes successfully without returning a token, using thecompletesmatcher as recommended in the coding guidelines.
866-880: LGTM! Helper method correctly updated to void return.The
_changePasswordhelper method signature and implementation have been consistently updated to reflect the void return type offinishPasswordReset, with the documentation correctly noting it no longer returns a session key.modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart (1)
122-149: LGTM! Public API correctly updated to align with OWASP guidance.The
finishPasswordResetmethod signature has been properly updated to returnvoidand accept the requirednewPasswordparameter. This aligns with the PR's objective to prevent automatic login after password reset, following OWASP security recommendations. The documentation correctly no longer mentions returning a session.modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart (4)
25-26: LGTM! Public constant enables consistent authentication method tracking.The visibility change from private to public is appropriate since this constant is now used in token issuance calls throughout the class.
105-111: LGTM! Scopes are now properly included in registration flow.The direct use of
_tokenManager.issueTokenwith scopes from the account creation result ensures that user scopes are properly included in the authentication token, addressing one of the PR's key objectives.
135-147: LGTM! Scopes are now properly included in login flow.The addition of
AuthUsers.getto retrieve the user's scopes (lines 135-139) followed by direct token issuance with those scopes (lines 141-147) ensures that scopes are properly included in the authentication token. While this adds an additional database query, it's necessary to fulfill the PR's objective of including scopes with login.
47-75: Now I'll check for any misleading test descriptions or improper uses of the return value:Verification complete: breaking change correctly implemented and OWASP-aligned.
OWASP guidance confirms that after password reset, users should login through the normal mechanism and all other sessions should be invalidated. The implementation correctly revoking all email-method tokens aligns with this security best practice.
All method signatures across the codebase have been consistently updated to
Future<void>, and all callers properly handle the void return type usingawait. The breaking change has been fully propagated.One issue: the test description at
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart:63states "returns auth session token," which is now misleading given the void return type. Update this to accurately reflect the new behavior (e.g., "succeeds and invalidates existing sessions").modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart (1)
82-88: Centralized token issuance looks solidRouting the login success through
_tokenIssuer.issueToken(with scopes included) keeps the provider aligned with the new shared issuance path and removes the custom session wiring that used to live here. Nice cleanup.modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dart (1)
108-114: Confirm Apple tokens include expected scopes.Now that we hand
account.scopesdirectly to theTokenIssuer, the issued Apple sessions are only as complete as the set returned byutils.authenticate(). Please double-check thatAuthUsers.create/AuthUsers.getpopulatescopesinside this transaction (especially when creating a brand-new account); otherwise we risk dropping defaults likeScope.userfrom the login response. Could you add or update a test to assert the Apple login flow still returns the expected scopes before merging?
25015c6 to
dd166a2
Compare
nielsenko
left a comment
There was a problem hiding this comment.
Some nits, but LGTM 👍
Goes through all supported IDP providers and ensures that scopes are included in successful logins.
Also removes creating a new token as the response from a password reset completion, as suggested by OWASP guidelines: https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html?utm_source=chatgpt.com
Tests for Google and Apple
Since we currently don't have a good way to mock the results from Google and Apple there are no tests included with this change. This will be added at a later stage.
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
If you have done any breaking changes, make sure to outline them here, so that they can be included in the notes for the next release.
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Refactor