Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis PR migrates Serverpod's authentication session handling from static Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Endpoint
participant TokenManager
participant AuthSessions
participant Database
rect rgb(200, 220, 255)
Note over Client,Database: Old Flow (Static AuthSessions)
Client->>Endpoint: Request
Endpoint->>AuthSessions: AuthSessions.createSession()
AuthSessions->>Database: Insert session
Database-->>AuthSessions: SessionInfo
AuthSessions-->>Endpoint: AuthSuccess
Endpoint-->>Client: Token
end
rect rgb(220, 255, 200)
Note over Client,Database: New Flow (Instance TokenManager)
Client->>Endpoint: Request
Endpoint->>TokenManager: tokenManager.issueToken(session, authUserId, method)
TokenManager->>AuthSessions: authSessions.createSession(...)
AuthSessions->>Database: Insert session
Database-->>AuthSessions: SessionInfo
AuthSessions-->>TokenManager: AuthSuccess
TokenManager-->>Endpoint: AuthSuccess (base64 encoded token)
Endpoint-->>Client: Token
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Areas requiring extra attention:
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
f2b8812 to
b2192e1
Compare
c720ba9 to
cd9c40a
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/test/unified_auth_handler_test.dart (1)
22-35: Restore test cleanup for AuthenticationTokens override
AuthenticationTokens.secretsTestOverrideis now set insetUpbut never cleared, so every later test in the suite keeps running with this mock configuration. That state leak will contaminate unrelated tests that rely on the default secrets. Please reinstate the teardown reset.setUp(() async { AuthenticationTokens.secretsTestOverride = AuthenticationTokenSecretsMock() ..setHs512Algorithm() ..refreshTokenHashPepper = 'some pepper 123'; session = sessionBuilder.build(); sasAuthSuccess = (await authSessions.createSession( session, authUserId: await createAuthUser(session), scopes: {const Scope('sas')}, method: 'test', )); jwtAuthSuccess = await AuthenticationTokens.createTokens( session, authUserId: await createAuthUser(session), scopes: {const Scope('jwt')}, method: 'test', ); }); + + tearDown(() { + AuthenticationTokens.secretsTestOverride = null; + });modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/src/session/business/auth_sessions.dart (1)
225-249: Honor the optional method filter when deleting sessions.We now accept an optional
method, but the query still removes every session for the user. Callers passingmethod(for example, to invalidate only one provider) will unexpectedly sign the user out everywhere. Serverpod’s own guidance shows filtering revocations by method when you only want to target a specific auth flow.(docs.serverpod.dev)Apply this diff so the filter is respected:
- final auths = await AuthSession.db.deleteWhere( - session, - where: (final row) => row.authUserId.equals(authUserId), - transaction: transaction, - ); + final auths = await AuthSession.db.deleteWhere( + session, + where: (final row) { + var predicate = row.authUserId.equals(authUserId); + if (method != null) { + predicate = predicate & row.method.equals(method); + } + return predicate; + }, + transaction: transaction, + );
🧹 Nitpick comments (3)
modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/test/integration/backwards_compatibility_test.dart (2)
10-14: Consider test isolation with shared token manager instance.The
tokenManageris instantiated once inmain()and shared across all tests. While this works for the current single test, it could cause isolation issues if:
- Additional tests are added that modify token manager state
- Tests run in parallel and share mutable state
Consider moving the token manager initialization into
setUp()to ensure each test gets a fresh instance, or document why sharing is safe in this context.setUp(() { final tokenManager = AuthSessionsTokenManager( config: AuthSessionConfig( sessionKeyHashPepper: 'test-pepper', ), ); session = sessionBuilder.build(); AuthBackwardsCompatibility.config = AuthBackwardsCompatibilityConfig( emailIDP: EmailIDP( config: config, tokenManager: tokenManager, ), ); });
17-20: Consider renaming variable to remove "new" prefix.The variable name
newEmailIDPincludes a "new" prefix that doesn't add clarity since there's no "old" EmailIDP to distinguish from in this file. Consider renaming to simplyemailIDPfor better readability.- final newEmailIDP = EmailIDP( + final emailIDP = EmailIDP( config: config, tokenManager: tokenManager, );And update the usage:
AuthBackwardsCompatibility.config = AuthBackwardsCompatibilityConfig( - emailIDP: newEmailIDP, + emailIDP: emailIDP, );modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/src/common/business/auth_config.dart (1)
54-63: Documentation mismatch foradditionalTokenManagers.Doc block still describes this parameter as “a map keyed by strategy name”, but the API now exposes it as a
List<TokenManager>. Please update the wording so integrators aren’t misled when wiring their own managers.Apply this diff to fix the text:
-/// [additionalTokenManagers] is a map of additional token managers keyed by strategy -/// name (e.g., 'jwt', 'session') that handle token lifecycle operations alongside the -/// [primaryTokenManager]. The default token manager is always included automatically. +/// [additionalTokenManagers] is a list of additional token managers that handle token +/// lifecycle operations alongside the [primaryTokenManager]. The primary manager is +/// always included automatically.
9c816b6 to
35fbfda
Compare
…g pattern for other methods).
35fbfda to
817e96e
Compare
|
@coderabbitai This PR implements a simple sever side session token manager, but it is currently not possible to control the additional properties such as how long a session lives. Could you create an issue that is a sub issue to #3856 to address this? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1976 🏁 Script executed: Length of output: 50 @SandPod: I've created issue #4128 to address the configuration of session token properties like lifetime and expiration policies. The issue is set up as a sub-issue to #3856 and includes:
You can view and edit the issue here: #4128 🧠 Learnings used |
nielsenko
left a comment
There was a problem hiding this comment.
I think we should avoid the anonymous record type
marcelomendoncasoares
left a comment
There was a problem hiding this comment.
Just a few questions, but everything looks good!
This PR moves managing server-side sessions into the AuthConfig.
It exposes a simple server-side session TokenManager that can issue tokens. Later, additional configuration for that manager will be added later.
This move allows endpoints and administrators to be token agnostic about what tokens exists in the system.
Follow up:
Additional information:
When modifying the implementation of the fake token managers it revealed that the tests for multi token manager are dependent on implementation details (accessing the storage and internal state of the fake token manager). These tests need to be refactored so that they only depend on the public interface.
The tests were now only patched to work, but need to be overlooked: a413de4
Related issue: #3856
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
If you have done any breaking changes, make sure to outline them here, so that they can be included in the notes for the next release.
Summary by CodeRabbit
Breaking Changes
AuthConfig.set()now required for setup instead of direct handler initializationNew Features