Skip to content

feat(auth2): Use url-safe base64 encoding for session key - #3834

Merged
tp merged 1 commit into
serverpod:mainfrom
tp:+-in-session-key
Jul 31, 2025
Merged

tp merged 1 commit into
serverpod:mainfrom
tp:+-in-session-key

Conversation

@tp

@tp tp commented Jul 31, 2025 •

Copy link
Copy Markdown
Contributor

I attempted to simplify the format further by encoding the entire dataset in one URL-safe base64 encoded String, but since the Serverpod Client takes the raw "session key" and sends it as a Basic authorization header, that failed (rightfully) in the Relic webserver, as the string did not contain a : anymore and thus did not match the user:pass schema.

Thus we have to stick with this format for now, unless we change the client/server (while keeping backwards compatibility). For this token as well as JWT it might be prudent to support the Bearer token pattern, and not further modify the values.

Summary by CodeRabbit

  • Refactor

    • Improved internal handling of session keys for authentication sessions, delegating parsing and building logic to dedicated utilities.
  • Tests

    • Added tests to ensure session keys are URL-safe, correctly formatted for authentication headers, and can be reliably encoded and decoded.

@coderabbitai

coderabbitai Bot commented Jul 31, 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

Session key parsing and building logic was refactored out of the authentication business logic into a new internal utility module. The new module provides functions for constructing and parsing session keys in a URL-safe format. Corresponding unit tests were added to verify correct encoding, decoding, and format compliance.

Changes

Cohort / File(s) Change Summary
Refactor session key handling in authentication business logic
modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/business/auth_sessions.dart
Removed inline session key parsing and building logic. Replaced with calls to new utility functions (tryParseSessionKey, buildSessionKey). Eliminated private constants and methods related to session key formatting. Updated to use new import for session key utilities.
Introduce session key utility module
modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/business/session_key.dart
Added a new internal module defining the session key format, with functions for building (buildSessionKey) and parsing (tryParseSessionKey) session keys, including error handling and logging. Introduced a typedef for the parsed session key data. All new APIs are marked as internal.
Add session key encoding/decoding tests
modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/session_key_test.dart
Added a new test suite to verify session key encoding produces URL-safe strings (no +), includes required delimiters, and is round-trippable through parsing. Tests include checks for correct suffix, presence of delimiters, and lossless decode/encode cycle.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server (auth_sessions.dart)
    participant SessionKeyUtil (session_key.dart)

    Client->>Server (auth_sessions.dart): Sends session key string
    Server (auth_sessions.dart)->>SessionKeyUtil (session_key.dart): tryParseSessionKey(session, key)
    SessionKeyUtil (session_key.dart)-->>Server (auth_sessions.dart): Returns (authSessionId, secret) or null
    Server (auth_sessions.dart)-->>Client: Proceeds with authentication result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
🧪 Generate unit tests

✅ Copyable Unit Test edits generated.

  • Create PR with unit tests
  • Commit unit tests in branch +-in-session-key
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tp
tp force-pushed the +-in-session-key branch 2 times, most recently from dbb836c to d4a17ad Compare July 31, 2025 07:57
@tp tp mentioned this pull request Jul 31, 2025
@tp
tp force-pushed the +-in-session-key branch from d4a17ad to 0f11c19 Compare July 31, 2025 08:19
@tp

tp commented Jul 31, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 31, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@tp
tp force-pushed the +-in-session-key branch from 0f11c19 to 6769a1e Compare July 31, 2025 08:43
@coderabbitai

coderabbitai Bot commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Note

Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@tp
tp requested a review from SandPod July 31, 2025 08:46
@coderabbitai

coderabbitai Bot commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Here are the copyable unit test edits:

Copyable Edits

modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/session_key_test.dart

@@ -8,55 +8,489 @@
 import 'integration/test_tools/serverpod_test_tools.dart';
 
 void main() {
+
   withServerpod(
-    'Given a session key based on a session secret which would result in `+` when base64 encoded,',
+    'Given buildSessionKey function with various inputs',
     (final sessionBuilder, final endpoints) {
       late Session session;
-      final secret = Uint8List.fromList([250]);
-      final authSessionId = const Uuid().v4obj();
-      late String sessionKey;
 
       setUp(() {
         session = sessionBuilder.build();
+      });
+
+      group('buildSessionKey edge cases', () {
+        test(
+          'when secret is empty, then creates a valid session key',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([]);
+
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            expect(sessionKey, isNotEmpty);
+            expect(sessionKey, startsWith('sas:'));
+            expect(sessionKey.split(':').length, equals(3));
+            expect(sessionKey, isNot(contains('+')));
+            expect(sessionKey, isNot(contains('/')));
+          },
+        );
+
+        test(
+          'when secret contains all possible byte values, then creates URL-safe key',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList(List.generate(256, (i) => i));
+
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            expect(sessionKey, isNotEmpty);
+            expect(sessionKey, startsWith('sas:'));
+            expect(sessionKey.split(':').length, equals(3));
+            expect(sessionKey, isNot(contains('+')));
+            expect(sessionKey, isNot(contains('/')));
+          },
+        );
+
+        test(
+          'when secret is a single zero byte, then creates valid session key',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([0]);
+
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            expect(sessionKey, isNotEmpty);
+            expect(sessionKey, startsWith('sas:'));
+            expect(sessionKey, endsWith(':AA=='));
+            expect(sessionKey.split(':').length, equals(3));
+          },
+        );
+
+        test(
+          'when secret is maximum single byte value (255), then creates valid session key',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([255]);
+
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            expect(sessionKey, isNotEmpty);
+            expect(sessionKey, startsWith('sas:'));
+            expect(sessionKey, endsWith(':_w=='));
+            expect(sessionKey.split(':').length, equals(3));
+          },
+        );
+
+        test(
+          'when called multiple times with same inputs, then produces identical keys',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([123, 45, 67]);
+
+            final sessionKey1 = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+            final sessionKey2 = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            expect(sessionKey1, equals(sessionKey2));
+          },
+        );
+
+        test(
+          'when called with different authSessionId but same secret, then produces different keys',
+          () {
+            final authSessionId1 = const Uuid().v4obj();
+            final authSessionId2 = const Uuid().v4obj();
+            final secret = Uint8List.fromList([123, 45, 67]);
+
+            final sessionKey1 = buildSessionKey(
+              authSessionId: authSessionId1,
+              secret: secret,
+            );
+            final sessionKey2 = buildSessionKey(
+              authSessionId: authSessionId2,
+              secret: secret,
+            );
+
+            expect(sessionKey1, isNot(equals(sessionKey2)));
+          },
+        );
+
+        test(
+          'when called with same authSessionId but different secret, then produces different keys',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret1 = Uint8List.fromList([123, 45, 67]);
+            final secret2 = Uint8List.fromList([123, 45, 68]);
 
-        assert(base64Encode(secret) == '+g==');
+            final sessionKey1 = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret1,
+            );
+            final sessionKey2 = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret2,
+            );
 
-        sessionKey = buildSessionKey(
-          authSessionId: authSessionId,
-          secret: secret,
+            expect(sessionKey1, isNot(equals(sessionKey2)));
+          },
         );
+
+        test(
+          'when building session key, then follows sas:uuid:secret format',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([1, 2, 3]);
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            final parts = sessionKey.split(':');
+            expect(parts.length, equals(3));
+            expect(parts[0], equals('sas'));
+            expect(parts[1], matches(RegExp(r'^[A-Za-z0-9_-]*={0,2}$'))); // URL-safe base64 UUID
+            expect(parts[2], matches(RegExp(r'^[A-Za-z0-9_-]*={0,2}$'))); // URL-safe base64 secret
+          },
+        );
+      });
+    },
+  );
+
+  withServerpod(
+    'Given tryParseSessionKey function with various inputs',
+    (final sessionBuilder, final endpoints) {
+      late Session session;
+
+      setUp(() {
+        session = sessionBuilder.build();
       });
 
-      test(
-        'when inspecting the key, then it does not contain a "+" because the encoding is URL safe.',
-        () {
-          expect(sessionKey, isNot(contains('+')));
-        },
-      );
+      group('tryParseSessionKey success cases', () {
+        test(
+          'when given a valid session key with empty secret, then parses correctly',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([]);
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
 
-      test(
-        'when inspecting the key, then it does at least one ":" to be usable as a Basic auth header.',
-        () {
-          expect(sessionKey, contains(':'));
-        },
-      );
+            final keyParts = tryParseSessionKey(session, sessionKey);
 
-      test(
-        'when inspecting the key, then contains the secret in the expected format.',
-        () {
-          expect(sessionKey, endsWith(':-g=='));
-        },
-      );
+            expect(keyParts, isNotNull);
+            expect(keyParts!.authSessionId, equals(authSessionId));
+            expect(keyParts.secret, equals(secret));
+          },
+        );
+
+        test(
+          'when given a valid session key with large secret, then parses correctly',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList(List.generate(100, (i) => i % 256));
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            final keyParts = tryParseSessionKey(session, sessionKey);
+
+            expect(keyParts, isNotNull);
+            expect(keyParts!.authSessionId, equals(authSessionId));
+            expect(keyParts.secret, equals(secret));
+          },
+        );
+
+        test(
+          'when given a session key with special byte values in secret, then parses correctly',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([0, 63, 127, 128, 191, 255]); // Various byte values
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            final keyParts = tryParseSessionKey(session, sessionKey);
+
+            expect(keyParts, isNotNull);
+            expect(keyParts!.authSessionId, equals(authSessionId));
+            expect(keyParts.secret, equals(secret));
+          },
+        );
+      });
+
+      group('tryParseSessionKey failure cases', () {
+        test(
+          'when given an empty string, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, '');
+
+            expect(keyParts, isNull);
+          },
+        );
 
-      test(
-        'when parsing the key, then it can be read again.',
-        () {
-          final keyParts = tryParseSessionKey(session, sessionKey);
+        test(
+          'when given a string without sas prefix, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'invalid:session:key');
 
-          expect(keyParts?.authSessionId, authSessionId);
-          expect(keyParts?.secret, secret);
-        },
-      );
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given a string with wrong prefix, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'wrong:session:key');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given a string with only sas prefix, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'sas');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given a string with sas but only one colon, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'sas:only-one-part');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given a string with too many parts, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'sas:part1:part2:part3:part4');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given invalid base64 UUID part, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'sas:invalid-base64!@#:dGVzdA==');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given invalid base64 secret part, then returns null',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final validUuidBase64 = base64Url.encode(authSessionId.toBytes());
+            final keyParts = tryParseSessionKey(session, 'sas:$validUuidBase64:invalid-base64!@#');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given empty parts after prefix, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'sas::');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given whitespace in session key, then returns null',
+          () {
+            final keyParts = tryParseSessionKey(session, 'sas: part1 : part2 ');
+
+            expect(keyParts, isNull);
+          },
+        );
+
+        test(
+          'when given valid format but invalid UUID bytes, then returns null',
+          () {
+            // Create invalid UUID bytes (not 16 bytes)
+            final invalidUuidBytes = Uint8List.fromList([1, 2, 3]); // Too short
+            final invalidUuidBase64 = base64Url.encode(invalidUuidBytes);
+            final keyParts = tryParseSessionKey(session, 'sas:$invalidUuidBase64:dGVzdA==');
+
+            expect(keyParts, isNull);
+          },
+        );
+      });
+
+      group('tryParseSessionKey roundtrip consistency', () {
+        test(
+          'when building and parsing multiple different session keys, then all roundtrip correctly',
+          () {
+            final testCases = [
+              Uint8List.fromList([]),
+              Uint8List.fromList([0]),
+              Uint8List.fromList([255]),
+              Uint8List.fromList([1, 2, 3, 4, 5]),
+              Uint8List.fromList(List.generate(32, (i) => i)),
+              Uint8List.fromList(List.generate(128, (i) => (i * 7) % 256)),
+              Uint8List.fromList([63, 255, 191]), // Creates special base64 chars
+            ];
+
+            for (final secret in testCases) {
+              final authSessionId = const Uuid().v4obj();
+              final sessionKey = buildSessionKey(
+                authSessionId: authSessionId,
+                secret: secret,
+              );
+              final keyParts = tryParseSessionKey(session, sessionKey);
+
+              expect(keyParts, isNotNull, reason: 'Failed for secret: $secret');
+              expect(keyParts!.authSessionId, equals(authSessionId), reason: 'AuthSessionId mismatch for secret: $secret');
+              expect(keyParts.secret, equals(secret), reason: 'Secret mismatch for secret: $secret');
+            }
+          },
+        );
+
+        test(
+          'when building 100 random session keys, then all roundtrip correctly',
+          () {
+            for (int i = 0; i < 100; i++) {
+              final authSessionId = const Uuid().v4obj();
+              final secretLength = (i % 50) + 1; // 1 to 50 bytes
+              final secret = Uint8List.fromList(
+                List.generate(secretLength, (index) => (index * 17 + i * 3) % 256)
+              );
+              
+              final sessionKey = buildSessionKey(
+                authSessionId: authSessionId,
+                secret: secret,
+              );
+              final keyParts = tryParseSessionKey(session, sessionKey);
+
+              expect(keyParts, isNotNull, reason: 'Failed for iteration $i');
+              expect(keyParts!.authSessionId, equals(authSessionId), reason: 'AuthSessionId mismatch for iteration $i');
+              expect(keyParts.secret, equals(secret), reason: 'Secret mismatch for iteration $i');
+            }
+          },
+        );
+      });
+
+      group('session key format validation', () {
+        test(
+          'when building session keys, then all follow sas:uuid:secret format pattern',
+          () {
+            for (int i = 0; i < 10; i++) {
+              final authSessionId = const Uuid().v4obj();
+              final secret = Uint8List.fromList(List.generate(i + 1, (index) => (index * 13) % 256));
+              final sessionKey = buildSessionKey(
+                authSessionId: authSessionId,
+                secret: secret,
+              );
+
+              // Should follow sas:uuid:secret format
+              expect(sessionKey, matches(RegExp(r'^sas:[A-Za-z0-9_-]+={0,2}:[A-Za-z0-9_-]*={0,2}$')));
+              expect(sessionKey, isNot(contains(' ')));
+              expect(sessionKey, isNot(contains('\n')));
+              expect(sessionKey, isNot(contains('\r')));
+              expect(sessionKey, isNot(contains('\t')));
+            }
+          },
+        );
+
+        test(
+          'when building session keys, then they are suitable for Basic auth headers',
+          () {
+            final authSessionId = const Uuid().v4obj();
+            final secret = Uint8List.fromList([1, 2, 3]);
+            final sessionKey = buildSessionKey(
+              authSessionId: authSessionId,
+              secret: secret,
+            );
+
+            // Should contain exactly 2 colons (making 3 parts)
+            expect(':'.allMatches(sessionKey).length, equals(2));
+            
+            // Should not contain characters that would break HTTP headers
+            expect(sessionKey, isNot(contains(' ')));
+            expect(sessionKey, isNot(contains('\n')));
+            expect(sessionKey, isNot(contains('\r')));
+            expect(sessionKey, isNot(contains('\t')));
+            expect(sessionKey, isNot(contains('"')));
+            expect(sessionKey, isNot(contains('\'')));
+          },
+        );
+
+        test(
+          'when building session key with various UUID versions, then all work correctly',
+          () {
+            final uuidVersions = [
+              const Uuid().v1obj(),
+              const Uuid().v4obj(),
+              const Uuid().v6obj(),
+              const Uuid().v7obj(),
+            ];
+
+            for (final authSessionId in uuidVersions) {
+              final secret = Uint8List.fromList([1, 2, 3]);
+              final sessionKey = buildSessionKey(
+                authSessionId: authSessionId,
+                secret: secret,
+              );
+              final keyParts = tryParseSessionKey(session, sessionKey);
+
+              expect(keyParts, isNotNull, reason: 'Failed for UUID version ${authSessionId.version}');
+              expect(keyParts!.authSessionId, equals(authSessionId));
+              expect(keyParts.secret, equals(secret));
+            }
+          },
+        );
+      });
+
+      group('error handling and logging', () {
+        test(
+          'when parsing malformed keys, then logs appropriate debug messages',
+          () {
+            // Test various malformed keys that should trigger different error paths
+            final malformedKeys = [
+              'wrong:prefix:here',
+              'sas:invalid-uuid:validbase64',
+              'sas:dmFsaWRfdXVpZA==:invalid-base64!',
+              'sas:too:many:parts:here',
+              'sas:',
+              'sas:only-one-part',
+            ];
+
+            for (final malformedKey in malformedKeys) {
+              final keyParts = tryParseSessionKey(session, malformedKey);
+              expect(keyParts, isNull, reason: 'Should return null for: $malformedKey');
+              // Note: We can't easily test log output without additional setup,
+              // but this ensures the function handles errors gracefully
+            }
+          },
+        );
+      });
     },
   );
 }

@SandPod

SandPod commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

@tp - Since the token no longer strictly adheres to the user:password format of the Basic header, perhaps it is better if we simply transmit our token as a bearer token instead? We now have 3 section more simialir to the JWT format.

After some reading it seems fine to have a custom format for the token: https://datatracker.ietf.org/doc/html/rfc6750

@tp

tp commented Jul 31, 2025

Copy link
Copy Markdown
Contributor Author

@SandPod Yes, I would love to switch to that format.

We just have to be careful with backwards compatibility on the server. I think currently we can not do an E2E test from one version to another, but I would love to have this checked with a "real" 2.9.x client against the server. Otherwise blind-coding this and going to a different code path for Bearer … auth headers would be easy (and at least the new approach easily tested).

So maybe this is a good first step, and then when the Bearer token support is added we can switch to the other commit (single base64 string) from this PR and use that instead. (It's already suggested as such on the JWT session manager implementation ticket.)

@SandPod

SandPod commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Sounds good to me! Then we just need to make sure that we don't release this before we switched over to the other header.

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

🚀

@tp
tp merged commit 927a7f5 into serverpod:main Jul 31, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 31, 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