Skip to content

fix: Include scopes with login and remove new token in password reset completion. - #4143

Merged
SandPod merged 6 commits into
serverpod:mainfrom
SandPod:include-scopes-in-login
Nov 3, 2025
Merged

SandPod merged 6 commits into
serverpod:mainfrom
SandPod:include-scopes-in-login

Conversation

@SandPod

@SandPod SandPod commented Nov 2, 2025 •

Copy link
Copy Markdown
Contributor

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

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.

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

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

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

    • Enhanced token management for Apple and Google sign-in authentication providers
    • Improved user permission scopes tracking during registration and login workflows
  • Bug Fixes

    • Refined transaction handling in authentication operations for better consistency and reliability
  • Refactor

    • Streamlined password reset flow
    • Updated account creation detection mechanisms

@coderabbitai

coderabbitai Bot commented Nov 2, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Change Summary
Apple IDP Refactoring
apple_idp.dart, apple_idp_utils.dart
Introduces _tokenIssuer field in AppleIDP; adds AppleIDP.fromSIWA() factory constructor. Replaces utils.createSession() with _tokenIssuer.issueToken() for token issuance. Updates account creation flag from authUserNewlyCreated to newAccount. Moves token creation responsibility from AppleIDPUtils to AppleIDP.
Email IDP Refactoring
email_idp.dart, email_idp_account_creation_util.dart, email_idp_base_endpoint.dart
Replaces private session creation helpers (_createSession, _destroyAllSessions) with direct tokenManager.issueToken() calls. Publishes method constant. Changes finishPasswordReset() return type from Future<AuthSuccess> to Future<void> and adds required newPassword parameter. Adds scopes field to EmailIDPCompleteAccountCreationResult.
Google IDP Refactoring
google_idp.dart, google_idp_utils.dart
Introduces _tokenIssuer field in GoogleIDP. Converts GoogleAccountDetails and GoogleAuthSuccess from classes to record typedefs. Removes _tokenIssuer dependency from GoogleIDPUtils; simplifies constructor. Changes authenticate() transaction parameter to required. Updates newAccount flag propagation and scopes handling.
Apple IDP Tests
test/apple/apple_account_admin_test.dart
Updates to use AppleIDP.fromSIWA() factory for creating IDP instances.
Email IDP Tests
test/email/email_idp/email_idp_finish_password_reset_test.dart, email_idp_finish_registration_test.dart, email_idp_login_test.dart
Replaces literal method strings with EmailIDP.method constant. Removes assertions on returned sessions for password reset. Adds scope validation tests. Updates test descriptions and setup to include scope assignments.
Integration Tests
tests/serverpod_new_auth_test/.../email_account_endpoint_test.dart, email_account_migration_test.dart, serverpod_test_tools.dart
Updates _changePassword() helper and finishPasswordReset() method signatures to return Future<void> instead of Future<AuthSuccess>. Removes token validation assertions after password reset operations.

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
Loading
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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • High logic density: Multiple interconnected IDPs (Apple, Email, Google) undergoing similar but distinct refactorings to TokenIssuer integration.
  • Structural changes: Conversion of Google utilities from classes to record typedefs; return type changes across Email endpoints; factory constructor additions.
  • Transaction handling updates: New DatabaseUtil abstraction for transaction-aware flows across multiple providers.
  • Heterogeneous changes: While the pattern is consistent (centralize token issuance), each provider applies it differently, requiring separate reasoning for Apple account linking, Email password reset semantics, and Google record-based types.
  • Test impact: Changes to assertions and test setup across 6+ test files; validator removal and new scope checks require context understanding.

Areas requiring extra attention:

  • Verify transaction parameter handling is consistent across all DatabaseUtil.runInTransactionOrSavepoint() calls
  • Confirm newAccount flag logic replaces authUserNewlyCreated/isNewUser consistently across providers
  • Validate scopes propagation from AuthUser models through all token issuance paths
  • Review the record typedef changes in google_idp_utils.dart for any breaking API shifts
  • Confirm email password reset removal of session token doesn't break client expectations (API contract change)

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description Check ⚠️ Warning The PR description provides a clear explanation of the changes being made (ensuring scopes are included in logins across all IDP providers and removing automatic token return from password reset per OWASP guidelines), and includes appropriate context with external references. However, the description has two significant gaps compared to the template requirements. First, the author did not list any issues that this PR fixes, which is explicitly required by the template ("You must list at least one issue"). Second, the "Breaking changes" section contains only the placeholder template text and is not filled in, despite the raw summary showing substantial breaking changes including: modified return types (finishPasswordReset: Future → Future), updated constructor signatures, changed field requirements in public types, and conversion of public classes to record typedefs. These breaking changes should be documented as specified in the template. The author should add at least one issue reference to the PR description to satisfy the required issue tracking requirement. Additionally, the "Breaking changes" section must be filled with a comprehensive list of all breaking changes, including the modified method signatures, updated return types, and changed public type definitions documented in the raw summary. This documentation is essential for release notes and communicating impact to users.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix: Include scopes with login and remove new token in password reset completion." is directly related to the changes present in the changeset. It accurately describes the two main objectives of the PR: adding scope support to login flows across IDP providers and removing automatic token generation after password reset, both of which are clearly reflected in the code modifications across Apple, Google, and Email IDP implementations. The title is specific, concise, and conveys meaningful information about the primary changes without being vague or generic.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SandPod

SandPod commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

- 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.
@SandPod
SandPod force-pushed the include-scopes-in-login branch from 32ddf9d to 25015c6 Compare November 2, 2025 17:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 finishPasswordReset now returns void (per OWASP guidance). The test also expects AuthSuccess but 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 transaction

Inside runInTransactionOrSavepoint every ORM call should reuse the provided transaction. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 048ea0d and 32ddf9d.

⛔ Files ignored due to path filters (3)
  • examples/auth/auth_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_client/lib/src/protocol/client.dart is 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 using dart 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.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_account_creation_util.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/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.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_login_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
  • tests/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.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_account_creation_util.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
  • modules/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.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/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.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/apple/apple_account_admin_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart
  • tests/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.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/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.dart
  • tests/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.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp.dart
  • modules/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.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/apple/business/apple_idp_utils.dart
  • modules/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.dart
  • tests/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.dart
  • tests/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.dart
  • modules/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.dart
  • modules/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.dart
  • modules/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 EmailIDPCompleteAccountCreationResult correctly captures the scopes from the newly created AuthUser and 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 scopes field 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.method instead 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 finishPasswordReset completes 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 finishPasswordReset signature has been properly updated to return Future<void> and accept the required newPassword parameter, aligning with the PR's OWASP-compliant changes.


1015-1048: LGTM! Consistent signature update across endpoints.

The password importing email account endpoint's finishPasswordReset has 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.update call 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 AuthSuccess returned 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 finishPasswordReset completes successfully without returning a token, using the completes matcher as recommended in the coding guidelines.


866-880: LGTM! Helper method correctly updated to void return.

The _changePassword helper method signature and implementation have been consistently updated to reflect the void return type of finishPasswordReset, 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 finishPasswordReset method signature has been properly updated to return void and accept the required newPassword parameter. 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.issueToken with 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.get to 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 using await. 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:63 states "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 solid

Routing 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.scopes directly to the TokenIssuer, the issued Apple sessions are only as complete as the set returned by utils.authenticate(). Please double-check that AuthUsers.create/AuthUsers.get populate scopes inside this transaction (especially when creating a brand-new account); otherwise we risk dropping defaults like Scope.user from the login response. Could you add or update a test to assert the Apple login flow still returns the expected scopes before merging?

@SandPod
SandPod force-pushed the include-scopes-in-login branch from 25015c6 to dd166a2 Compare November 2, 2025 17:33
@SandPod
SandPod marked this pull request as ready for review November 2, 2025 17:39
@SandPod
SandPod requested a review from a team November 2, 2025 17:40

@nielsenko nielsenko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but LGTM 👍

@SandPod
SandPod merged commit 6d0fb7f into serverpod:main Nov 3, 2025
@SandPod
SandPod deleted the include-scopes-in-login branch November 3, 2025 16:38
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants