Skip to content

refactor!: Make passkey IDP conform to IDP pattern. - #4144

Merged
SandPod merged 10 commits into
serverpod:mainfrom
SandPod:3856-move-passkey-to-IDP-pattern
Nov 4, 2025
Merged

SandPod merged 10 commits into
serverpod:mainfrom
SandPod:3856-move-passkey-to-IDP-pattern

Conversation

@SandPod

@SandPod SandPod commented Nov 3, 2025 •

Copy link
Copy Markdown
Contributor

Moves the Passkey Identity provider to conform to the IDP pattern.

This PR does not include tests for the new methods because it was difficult to create new secrets.
A follow-up test PR will be added to address this.

Closes: #3856

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

This includes breaking changes but only affects a non-published package.

Summary by CodeRabbit

  • New Features

    • Added Passkey-based authentication enabling users to register and authenticate using passpkeys, expanding available authentication options.
  • Refactor

    • Restructured internal passkey authentication architecture with improved configuration management and administrative tools for managing passkey accounts.

@coderabbitai

coderabbitai Bot commented Nov 3, 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 introduces Passkey-based identity provider support by implementing PasskeyIDP and PasskeyIDPUtils, adding a PasskeyIdentityProviderFactory, and registering the provider with AuthServices in the example auth server. The implementation refactors existing static PasskeyAccounts utilities into an instance-based architecture supporting transaction-aware operations, token issuance, and admin functions.

Changes

Cohort / File(s) Summary
Passkey IDP Core Implementation
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart, ...passkey_idp_utils.dart, ...passkey_idp_admin.dart, ...passkey_idp_config.dart
Introduces PasskeyIDP as the main orchestrator for challenge creation, registration, and login flows; replaces static PasskeyAccounts with instance-based PasskeyIDPUtils handling challenge consumption, authentication, and passkey account management; adds PasskeyIDPAdmin for administrative operations; renames PasskeyAccountConfig to PasskeyIDPConfig.
Passkey Endpoints
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart, examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
Replaces PasskeyAccountBaseEndpoint with PasskeyIDPBaseEndpoint providing createChallenge, register, and login methods that delegate to PasskeyIDP; example server adds PasskeyIDPEndpoint extending the new base endpoint.
Factory and Public API Updates
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart, ...lib/providers/passkey.dart, ...lib/src/providers/passkey/passkey.dart
Adds PasskeyIdentityProviderFactory implementing dependency-injected PasskeyIDP construction; exports the factory from the passkey provider library; updates module exports to surface new PasskeyIDP-based classes and remove legacy PasskeyAccounts/PasskeyAccountConfig.
Legacy Code Removal
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_accounts_admin.dart, ...endpoints/passkey_account_base_endpoint.dart
Removes PasskeyAccountsAdmin utility class and PasskeyAccountBaseEndpoint abstract class, consolidating functionality into PasskeyIDPAdmin and PasskeyIDPBaseEndpoint.
Example Server Configuration
examples/auth/auth_server/lib/server.dart
Registers PasskeyIdentityProviderFactory with AuthServices.set alongside Google and Apple providers using PasskeyIDPConfig with 30-second challenge lifetime and localhost hostname.
Tests
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart, ...passkey_idp_test.dart
Updates test setup to instantiate PasskeyIDP with tokenManager and PasskeyIDPConfig; replaces PasskeyAccounts method calls with PasskeyIDP and admin method invocations; adjusts timing calculations and assertions to align with new API.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Endpoint as PasskeyIDPEndpoint
    participant BaseEP as PasskeyIDPBaseEndpoint
    participant IDP as PasskeyIDP
    participant Utils as PasskeyIDPUtils
    participant DB as Database
    participant TokenMgr as TokenManager

    rect rgb(240, 248, 255)
    Note over Client,TokenMgr: Challenge Creation Flow
    Client->>Endpoint: createChallenge(session)
    Endpoint->>BaseEP: createChallenge(session)
    BaseEP->>IDP: createChallenge(session)
    IDP->>Utils: createChallenge(session)
    Utils->>DB: Create PasskeyChallenge record
    DB-->>Utils: Challenge ID, Challenge data
    Utils-->>IDP: PasskeyChallenge
    IDP-->>BaseEP: PasskeyChallengeResponse (id, challenge)
    BaseEP-->>Endpoint: PasskeyChallengeResponse
    Endpoint-->>Client: PasskeyChallengeResponse
    end

    rect rgb(240, 255, 240)
    Note over Client,TokenMgr: Registration Flow
    Client->>Endpoint: register(session, request, challengeId)
    Endpoint->>BaseEP: register(session, request)
    BaseEP->>IDP: register(session, authUserId, request)
    IDP->>Utils: registerPasskey(session, authUserId, request)
    Utils->>Utils: _consumeChallenge(session, challengeId)
    Utils->>DB: Delete/Validate PasskeyChallenge
    Utils->>DB: Create PasskeyAccount record
    DB-->>Utils: Success
    Utils-->>IDP: Void
    IDP-->>BaseEP: Void
    BaseEP-->>Endpoint: Void
    Endpoint-->>Client: Success
    end

    rect rgb(255, 240, 245)
    Note over Client,TokenMgr: Login Flow
    Client->>Endpoint: login(session, loginRequest)
    Endpoint->>BaseEP: login(session, loginRequest)
    BaseEP->>IDP: login(session, request)
    IDP->>Utils: authenticate(session, request)
    Utils->>Utils: _consumeChallenge(session, challengeId)
    Utils->>DB: Verify against PasskeyAccount
    DB-->>Utils: authUserId
    Utils-->>IDP: authUserId
    IDP->>DB: Load AuthUser
    DB-->>IDP: AuthUser
    alt User is blocked
        IDP-->>BaseEP: AuthUserBlockedException
    else User is active
        IDP->>TokenMgr: issueToken(authUserId)
        TokenMgr-->>IDP: AuthSuccess (token)
        IDP-->>BaseEP: AuthSuccess
        BaseEP-->>Endpoint: AuthSuccess
        Endpoint-->>Client: AuthSuccess
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • PasskeyIDPUtils refactoring: Complex transaction-aware operations, challenge consumption logic with error handling (NotFound, Expired exceptions), and bulk deletion patterns require careful verification.
  • PasskeyIDP token issuance contract: Review how tokenIssuer is wired, transaction propagation, and integration with blocked user checks and AuthSuccess response construction.
  • PasskeyIdentityProviderFactory implementation: Verify dependency injection pattern, token manager override handling, and correct initialization of PasskeyIDP instances.
  • Test coverage updates: Ensure all new PasskeyIDP/PasskeyIDPUtils methods are adequately tested and timing/clock-based assertions remain valid.
  • Export changes and public API surface: Cross-check that removed PasskeyAccounts/PasskeyAccountConfig exports don't break downstream dependencies and new exports are correctly registered.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description provides a brief summary of the changes ('Moves the Passkey Identity provider to conform to the IDP pattern') and references a closed issue (#3856). However, the main description section lacks substantial detail about the what and why of the changes. The pre-launch checklist is mostly unchecked, indicating incomplete adherence to contribution guidelines. The PR notes that tests were not included due to difficulty creating new secrets, with a follow-up test PR planned. Breaking changes are acknowledged but not documented. To improve this PR description, provide more detailed explanation of: (1) what architectural patterns and components were changed to conform to the IDP pattern, (2) why this refactoring was necessary, (3) document the breaking changes in the 'Breaking changes' section with specifics about which APIs changed and how consumers should migrate, and (4) verify and update the pre-launch checklist items to accurately reflect the work completed.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'refactor!: Make passkey IDP conform to IDP pattern' clearly and specifically describes the main change in the changeset. It accurately reflects that the PR refactors the passkey identity provider to follow the standard IDP pattern, which is the core objective evident from the code changes replacing PasskeyAccounts with PasskeyIDP and related infrastructure updates. The title is concise, specific, and directly summarizes the primary change from the developer's perspective.

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 force-pushed the 3856-move-passkey-to-IDP-pattern branch from 28a864e to 895d4be Compare November 3, 2025 11:59
@SandPod

SandPod commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 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.

@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: 2

🧹 Nitpick comments (3)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart (1)

35-43: Update test descriptions to reflect PasskeyIDP.

These test titles still say PasskeyAccounts..., but the setup now exercises PasskeyIDP. Renaming the descriptions (and the similar one below) will keep the intent obvious when reading test output.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart (1)

58-75: Refresh test names to the PasskeyIDP terminology.

The description still mentions PasskeyAccounts..., which no longer matches the system under test. Please update this (and the other occurrences in this file) to say PasskeyIDP so the output mirrors the refactor.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart (1)

22-34: Consider explicit error handling for unauthenticated sessions.

The null assertion operator on line 31 will throw a generic null check error if the user is not authenticated. For better developer experience and clearer error messages, consider explicit validation:

Apply this diff to add explicit error handling:

   Future<void> register(
     final Session session, {
     required final PasskeyRegistrationRequest registrationRequest,
   }) async {
+    final authInfo = await session.authenticated;
+    if (authInfo == null) {
+      throw UnauthorizedException(
+        'User must be authenticated to register a passkey',
+      );
+    }
     await passkeyIDP.register(
       session,
-      authUserId: (await session.authenticated)!.authUserId,
+      authUserId: authInfo.authUserId,
       request: registrationRequest,
     );
   }

Note: Verify that UnauthorizedException is available from the imported packages.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6becf50 and 895d4be.

⛔ Files ignored due to path filters (6)
  • examples/auth/auth_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
  • examples/auth/auth_client/lib/src/protocol/protocol.dart is excluded by !**/lib/src/protocol/**
  • examples/auth/auth_server/lib/src/generated/endpoints.dart is excluded by !**/generated/**
  • examples/auth/auth_server/lib/src/generated/protocol.dart is excluded by !**/generated/**
  • examples/auth/auth_server/lib/src/generated/protocol.yaml is excluded by !**/generated/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
📒 Files selected for processing (14)
  • examples/auth/auth_server/lib/server.dart (3 hunks)
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_accounts_admin.dart (0 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_admin.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_config.dart (2 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.dart (3 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_account_base_endpoint.dart (0 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart (2 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart (11 hunks)
💤 Files with no reviewable changes (2)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_accounts_admin.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_account_base_endpoint.dart
🧰 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/lib/src/providers/passkey/business/passkey_idp_admin.dart
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.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/passkey/business/passkey_idp_admin.dart
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.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/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
🧠 Learnings (17)
📓 Common learnings
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.
Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/models/passkey_challenge.spy.yaml:1-12
Timestamp: 2025-08-26T12:25:49.153Z
Learning: The Passkey authentication provider in Serverpod deletes used challenges to prevent replay attacks and maintain database cleanliness.
📚 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/lib/src/providers/passkey/business/passkey_idp_admin.dart
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.dart
📚 Learning: 2025-08-26T12:25:49.153Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/models/passkey_challenge.spy.yaml:1-12
Timestamp: 2025-08-26T12:25:49.153Z
Learning: The Passkey authentication provider in Serverpod deletes used challenges to prevent replay attacks and maintain database cleanliness.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_admin.dart
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.dart
📚 Learning: 2025-08-26T12:25:49.153Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/models/passkey_challenge.spy.yaml:1-12
Timestamp: 2025-08-26T12:25:49.153Z
Learning: In the Serverpod Passkey authentication implementation, challenge expiry is handled via the PasskeyAccountConfig's challengeLifetime setting rather than storing explicit expiresAt timestamps in the database.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_admin.dart
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart
  • examples/auth/auth_server/lib/server.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.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/lib/src/providers/passkey/business/passkey_idp_admin.dart
  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_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:

  • examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.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/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_idp_utils.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:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.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:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_admin_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/providers/passkey.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.dart
📚 Learning: 2025-10-30T10:11:34.781Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4127
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_account_base_endpoint.dart:11-16
Timestamp: 2025-10-30T10:11:34.781Z
Learning: In Serverpod authentication endpoints, SandPod prefers eager initialization of AuthConfig-dependent fields (e.g., `final TokenManager tokenManager = AuthConfig.instance.tokenManager;`) rather than lazy getters, to detect misconfiguration at server startup rather than deferring errors until the first request to the endpoint.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_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/passkey/passkey_idp_test.dart
📚 Learning: 2025-08-20T13:29:38.181Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 3904
File: modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/test/jwt/integration/authentication_tokens_test.dart:141-143
Timestamp: 2025-08-20T13:29:38.181Z
Learning: In Serverpod test files, SandPod prefers to avoid redundant null-checks in tests when the preconditions guarantee non-null values. They consider such defensive assertions as "redundant bloat" when the test environment is controlled and the implementation guarantees the presence of values like refreshToken.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/passkey/passkey_idp_test.dart
📚 Learning: 2025-07-23T13:18:31.864Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3820
File: modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server/lib/src/endpoints/user_profile_base_endpoint.dart:8-8
Timestamp: 2025-07-23T13:18:31.864Z
Learning: Abstract Endpoint classes in Serverpod should end with the "BaseEndpoint" suffix in their name (e.g., UserProfileBaseEndpoint). This naming convention should be enforced consistently across the codebase.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.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/passkey/passkey.dart
  • examples/auth/auth_server/lib/server.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:

  • examples/auth/auth_server/lib/server.dart
📚 Learning: 2025-07-01T13:01:27.054Z
Learnt from: exaby73
Repo: serverpod/serverpod PR: 3741
File: modules/serverpod_auth/serverpod_auth_server/analysis_options.yaml:14-16
Timestamp: 2025-07-01T13:01:27.054Z
Learning: In Serverpod, first-party packages like serverpod_auth_server can appropriately use blanket `invalid_use_of_internal_member: ignore` directives in their analysis_options.yaml since they use internal Database methods internally without exposing them in their public APIs to end users.

Applied to files:

  • examples/auth/auth_server/lib/server.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: In the sign_in_with_apple_server package, the `decodeAppleServerNotification` method performs complete JWT signature verification against Apple's published public keys. It fetches keys from https://appleid.apple.com/auth/keys, validates the audience and issuer, and cryptographically verifies the JWT signature. This means webhook handlers using this method already have proper security against spoofed notifications without needing additional signature verification code.

Applied to files:

  • examples/auth/auth_server/lib/server.dart
🔇 Additional comments (3)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart (3)

15-20: LGTM!

The createChallenge method correctly delegates to the underlying IDP implementation. Not requiring authentication is appropriate since challenges are needed before authentication can occur.


36-42: LGTM!

The login method correctly delegates to the underlying IDP implementation and returns the authentication result. The implementation is straightforward and secure.


9-13: The original review comment is based on incorrect assumptions about Dart semantics and the existing error handling.

The AuthServices.getIdentityProvider<T>() method already provides a descriptive StateError message that clearly explains what went wrong and how to fix it: "Provider for $T is not registered. To register this provider, add its IdentityProviderFactory to the identityProviders list when calling AuthServices.set(). Example: AuthServices.set(defaultTokenManager: ..., identityProviders: [YourProviderFactory()])"

Regarding override semantics: In Dart, late final fields can be overridden in subclasses by implementing a getter override. The documentation comment stating "If you want to use a different instance, override this getter" is accurate and follows standard Dart patterns.

Likely an incorrect or invalid review comment.

@SandPod
SandPod force-pushed the 3856-move-passkey-to-IDP-pattern branch 2 times, most recently from 15cb9f3 to 2279eb2 Compare November 3, 2025 15:52
@SandPod

SandPod commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai Could you open an issue to address the missing tests in this PR.

@SandPod
SandPod marked this pull request as ready for review November 3, 2025 16:34
@coderabbitai

coderabbitai Bot commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for test files related to the new passkey IDP classes
echo "=== Searching for existing passkey IDP test files ==="
fd -e dart -p test | rg -i passkey

echo -e "\n=== Checking test coverage for new classes ==="
# Check for tests of PasskeyIdentityProviderFactory
echo "PasskeyIdentityProviderFactory tests:"
rg -l "PasskeyIdentityProviderFactory" --type=dart -g '*test*.dart' || echo "No tests found"

echo -e "\nPasskeyIDPBaseEndpoint tests:"
rg -l "PasskeyIDPBaseEndpoint" --type=dart -g '*test*.dart' || echo "No tests found"

echo -e "\nPasskeyIDPEndpoint tests:"
rg -l "PasskeyIDPEndpoint" --type=dart -g '*test*.dart' || echo "No tests found"

echo -e "\n=== Listing test file contents briefly ==="
# List the existing passkey test files to understand what IS tested
fd 'passkey.*test\.dart$' --type f -x echo "File: {}"

Length of output: 742


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for missing test coverage
gh issue create \
  --title "Add missing tests for Passkey IDP refactoring" \
  --body "## Context
This issue tracks missing test coverage for the Passkey IDP refactoring introduced in PR #4144.

## Missing Test Coverage

The following components were introduced or modified in the refactoring but lack dedicated test coverage:

1. **PasskeyIdentityProviderFactory** - The factory class that creates PasskeyIDP instances
   - Location: \`modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/integrations/passkey_identity_provider_factory.dart\`
   - Should test: factory construction, configuration passing, and IDP instantiation

2. **PasskeyIDPBaseEndpoint** - The abstract base endpoint for Passkey authentication
   - Location: \`modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart\`
   - Should test: createChallenge, register, and login method contracts

3. **PasskeyIDPEndpoint** - The example implementation in the auth server
   - Location: \`examples/auth/auth_server/lib/src/endpoints/passkey_idp_endpoint.dart\`
   - Should test: endpoint behavior and integration with PasskeyIDPBaseEndpoint

## Existing Coverage

The following components already have test coverage:
- PasskeyIDP (tested in \`passkey_idp_test.dart\`)
- PasskeyIDPAdmin (tested in \`passkey_idp_admin_test.dart\`)

## Related
- PR: #4144
- Requested by: @SandPod in https://github.com/serverpod/serverpod/pull/4144" \
  --assignee SandPod

Length of output: 50


@SandPod, I've created issue #4147 to track the missing test coverage: #4147

The issue identifies three components that need tests:

  1. PasskeyIdentityProviderFactory - for factory construction and IDP instantiation
  2. PasskeyIDPBaseEndpoint - for the base endpoint method contracts
  3. PasskeyIDPEndpoint - for the example implementation

The issue has been assigned to you and includes backlinks to this PR and comment.


🧠 Learnings used
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.

Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.794Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.

Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/models/passkey_challenge.spy.yaml:1-12
Timestamp: 2025-08-26T12:25:49.153Z
Learning: The Passkey authentication provider in Serverpod deletes used challenges to prevent replay attacks and maintain database cleanliness.

@SandPod
SandPod requested a review from a team November 3, 2025 16:37

@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.

Question regarding late

@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.

I have a few comments regarding how to avoid late final members that are initialized in the ctor anyway, and perhaps using User instead of trafficking in UuidValue for user id.

However, feel free to ignore them, if you disagree.

@SandPod
SandPod force-pushed the 3856-move-passkey-to-IDP-pattern branch from 2279eb2 to 5798127 Compare November 4, 2025 08:31
@SandPod
SandPod merged commit 94f11a9 into serverpod:main Nov 4, 2025
@SandPod
SandPod deleted the 3856-move-passkey-to-IDP-pattern branch November 4, 2025 09:01
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 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.

Add shared configuration interface for authentication providers with generalized configuration list

2 participants