Skip to content

feat: Add session token configuration properties to AuthSessionsConfig - #4142

Merged
SandPod merged 8 commits into
mainfrom
copilot/add-session-token-configuration
Nov 4, 2025
Merged

SandPod merged 8 commits into
mainfrom
copilot/add-session-token-configuration

Conversation

Copilot AI commented Nov 2, 2025 •

Copy link
Copy Markdown
Contributor

Add configuration for session token properties in AuthSessionsConfig

This PR addresses the requirements for adding configuration options to control session token properties in the authentication system.

Summary

Extended the AuthSessionsConfig class with two optional configuration properties to control session behavior:

  1. defaultSessionLifetime - Controls absolute session expiration time
  2. defaultSessionInactivityTimeout - Controls inactivity-based session expiration

Implementation Details

Configuration Properties

defaultSessionLifetime: Duration?

  • When set, new sessions expire at creation time + this duration
  • Can be overridden per-session via expiresAt parameter
  • Defaults to null (no absolute expiration)

defaultSessionInactivityTimeout: Duration?

  • When set, sessions expire if unused for this duration
  • Can be overridden per-session via expireAfterUnusedFor parameter
  • Defaults to null (no inactivity timeout)

Code Changes

  • auth_sessions_config.dart: Added 2 optional properties with validation
  • auth_sessions.dart: Updated createSession to apply config defaults
  • Tests: Added 8 unit tests + comprehensive integration tests in auth_sessions_create_session_test.dart (44 tests passing)

Example Usage

// Session with 7-day absolute expiration
final authSessions = AuthSessions(
  config: AuthSessionsConfig(
    sessionKeyHashPepper: 'your-secret-pepper',
    defaultSessionLifetime: const Duration(days: 7),
  ),
);

// Session with 2-hour inactivity timeout
final authSessions = AuthSessions(
  config: AuthSessionsConfig(
    sessionKeyHashPepper: 'your-secret-pepper',
    defaultSessionInactivityTimeout: const Duration(hours: 2),
  ),
);

// Combined configuration
final authSessions = AuthSessions(
  config: AuthSessionsConfig(
    sessionKeyHashPepper: 'your-secret-pepper',
    defaultSessionLifetime: const Duration(days: 30),
    defaultSessionInactivityTimeout: const Duration(hours: 24),
  ),
);

Testing

  • ✅ 44 unit tests passing (includes 8 config validation tests)
  • ✅ All existing tests pass (backward compatibility verified)
  • ✅ Code formatted and analyzed (no issues)

Backward Compatibility

✅ Fully backward compatible - All new parameters are optional and default to null. Existing applications continue to work without any changes.

Acceptance Criteria Status

  • ✅ Define session configuration properties
  • ✅ Expose configuration through AuthSessionsConfig
  • ✅ Update AuthSessionsTokenManager to respect configured session properties (via AuthSessions)
  • ✅ Add validation for configuration values
  • ✅ Add documentation with examples (inline docs + PR examples)
  • ✅ Add tests for various session configuration scenarios

Fixes #4128

Original prompt

This section details on the original issue you should resolve

<issue_title>Add configuration for session token properties (lifetime, expiration, etc.) in AuthConfig</issue_title>
<issue_description>## Summary

The server-side session token manager implemented in PR #4127 currently does not expose configuration options for controlling session properties such as session lifetime, expiration policies, and other token-related settings.

Parent Issue

This is a sub-issue of #3856 - Add shared configuration interface for authentication providers with generalized configuration list.

Current State

PR #4127 introduces AuthSessionsTokenManager which manages server-side session tokens, but session configuration properties are not currently exposed through the AuthConfig interface.

Requirements

Add configuration options to control session token properties, including:

  • Session lifetime/duration (time until expiration)
  • Session expiration policies (absolute vs. sliding expiration)
  • Session refresh policies
  • Maximum concurrent sessions per user
  • Session timeout settings
  • Other relevant token/session properties

Proposed Solution

Extend the AuthSessionConfig or create a new configuration class that can be passed to AuthSessionsTokenManager through the AuthConfig setup, allowing developers to customize session behavior based on their application requirements.

References

Acceptance Criteria

  • Define session configuration properties
  • Expose configuration through AuthConfig or related configuration classes
  • Update AuthSessionsTokenManager to respect configured session properties
  • Add validation for configuration values
  • Add documentation with examples
  • Add tests for various session configuration scenarios</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

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


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

Copilot AI changed the title [WIP] Add configuration for session token properties in AuthConfig feat: Add session token configuration properties to AuthSessionsConfig Nov 2, 2025
Copilot AI requested a review from SandPod November 2, 2025 17:24
@SandPod

SandPod commented Nov 2, 2025

Copy link
Copy Markdown
Contributor

@copilot Changes look good, but please remove the max concurrent sessions options along with its implementation.

Copilot AI commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Changes look good, but please remove the max concurrent sessions options along with its implementation.

Removed the maxConcurrentSessionsPerUser feature and all related implementation in commit fab40f6. The PR now only includes defaultSessionLifetime and defaultSessionInactivityTimeout configuration options.

@SandPod

SandPod commented Nov 2, 2025

Copy link
Copy Markdown
Contributor

@copilot Please remove the entry in the changelog

Copilot AI commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Please remove the entry in the changelog

Removed the changelog entry in commit 72b352d.

@SandPod

SandPod commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

@copilot please rename auth_sessions_config_integration_test.dart to auth_sessions_create_session_test.dart.

Copilot AI commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

@copilot please rename auth_sessions_config_integration_test.dart to auth_sessions_create_session_test.dart.

Renamed the file in commit 7929ddb.

@SandPod
SandPod marked this pull request as ready for review November 3, 2025 17:26
@SandPod
SandPod requested a review from a team November 3, 2025 17:26

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

👍

Only a nit on a doc comment

Co-authored-by: Kasper Overgård Nielsen <[email protected]>
@SandPod
SandPod merged commit d92b23b into main Nov 4, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 2025
@SandPod

SandPod commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

@coderabbitai Could you create these 2 new issues:

  1. Add an extra claims callback to the JWT token issuer so that a user can centrally configure how to fetch extra claims when a new JWT token is issued.
  2. Make it configurable what scopes should be assigned when new AuthUsers are created.

@SandPod
SandPod deleted the copilot/add-session-token-configuration branch November 4, 2025 08:51
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 configuration for session token properties (lifetime, expiration, etc.) in AuthConfig

3 participants