Skip to content

Create Session based token management system - #43

Closed
spa-raj wants to merge 0 commit into
FailproofAI:mainfrom
spa-raj:main
Closed

Create Session based token management system#43
spa-raj wants to merge 0 commit into
FailproofAI:mainfrom
spa-raj:main

Conversation

@spa-raj

@spa-raj spa-raj commented Jul 12, 2025

Copy link
Copy Markdown
Contributor

fixes #42

This pull request introduces significant changes to the api-server application, focusing on session and token management, as well as configuration updates for the development environment. The most important changes include implementing session and token models, adding services to handle session and token operations, modifying the create_token flow, and updating project settings for IntelliJ IDEA.

Session and Token Management:

  • Session Model (api-server/app/auth/models/session_database_model.py): Added a Session model to manage user sessions, including fields for session status, expiration, and last activity. Includes methods for creating and updating sessions.
  • Token Model (api-server/app/auth/models/token_database_model.py): Added a Token model to manage user tokens, including fields for session association, expiration, and status. Includes indexing for efficient querying.
  • Session and Token Status Enums: Introduced SessionStatusEnum and TokenStatusEnum to define valid statuses for sessions and tokens, such as ACTIVE, INACTIVE, and BLACKLISTED. [1] [2]
  • Session Manager Service (api-server/app/auth/services/session_manager.py): Implemented logic for creating, updating, and ending sessions, including handling token expiration and enforcing a maximum token limit per session.
  • Token Manager Service (api-server/app/auth/services/token_manager.py): Added functionality to create tokens, retrieve active tokens for a session or user, and blacklist tokens.

Updates to create_token Flow:

  • Controller Modifications (api-server/app/auth/controllers/create_token.py): Updated the create_token method to integrate session creation and token storage in the database. Added error handling for session creation failures. [1] [2]

Project Configuration for IntelliJ IDEA:

  • IDE Settings (.idea/.gitignore, .idea/exospherehost.iml, .idea/inspectionProfiles, .idea/misc.xml, .idea/modules.xml, .idea/vcs.xml): Added configuration files for IntelliJ IDEA to ignore default files, define module settings, inspection profiles, and version control mappings. [1] [2] [3] [4] [5] [6] [7]

Miscellaneous Changes:

  • Database Initialization (api-server/app/main.py): Updated Beanie initialization to include Session and Token models for database operations. [1] [2]
  • Environment Variable for Max Tokens (api-server/run.py): Added support for configuring the maximum number of tokens per session via a command-line argument and environment variable.
  • Project Packaging (api-server/pyproject.toml): Updated packaging settings to include the app directory.

@NiveditJain

Copy link
Copy Markdown
Member

Hey @spa-raj, thanks for the PR.
Meanwhile, I am reviewing it. Can you please fix these lint issues?

@NiveditJain
NiveditJain self-requested a review July 13, 2025 05:55

@NiveditJain NiveditJain left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as discussed over our old discord channel lets move it to redis based approach without a limit on number of tokens per user, we can discuss further in our updated channel here: https://discord.com/channels/816925020973432832/1393988900162371614

Comment thread api-server/pyproject.toml Outdated
Comment on lines +16 to +17
[tool.setuptools.packages.find]
include = ["app*"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is this change?

@spa-raj spa-raj closed this Jul 15, 2025
@spa-raj

spa-raj commented Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

I will create a separate PR for Redis implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Session based token management system

2 participants