feat: Implement User Authentication and Session Ownership#5
Merged
DhruvSrikanth merged 24 commits intomainfrom Apr 23, 2025
Merged
feat: Implement User Authentication and Session Ownership#5DhruvSrikanth merged 24 commits intomainfrom
DhruvSrikanth merged 24 commits intomainfrom
Conversation
- Introduced `auth.py` for managing API key storage and retrieval. - Updated `__init__.py` to allow custom base URL via environment variable. - Enhanced API functions in `api.py` to accept authentication headers. - Implemented login flow in `cli.py` for user authentication and session management. - Improved command-line interface with subcommands for running optimizations and logging out.
…asks, update API key setup instructions, and introduce `weco run` and `weco logout` commands with detailed examples and argument descriptions.
…g for authentication, update README.md to reflect changes in login options and API key storage location, and improve command-line prompts for user clarity.
- Introduced a new parser definition for the "logout" command in `cli.py` to allow users to log out and clear saved API keys.
…ent. Added handling for 202 Accepted status with authorization pending, and removed redundant checks for authorization pending in 400 errors. Enhanced error reporting for unexpected responses.
This commit merges the user authentication feature branch (`feat-user-auth`) into main and resolves the resulting merge conflicts.
Key changes include:
- **Resolved Merge Conflicts:** Addressed conflicts in `README.md` and `weco/cli.py`.
- **Integrated User Authentication:**
- Introduced `weco run` and `weco logout` subcommands.
- Implemented the device authentication grant flow (`perform_login`) for user login via the CLI.
- Added logic to prompt the user to log in or proceed anonymously if no Weco API key is found.
- Updated API calls (`api.py`, `cli.py`) to include `Authorization` headers when logged in and pass client LLM keys in `metadata`.
- Added `session_id` display to the log path in the `SummaryPanel` (`panels.py`).
- Updated `README.md` to document the login/logout commands and the device flow.
- **Integrated `main` Branch Features:**
- Preserved `main`'s README structure and content for conflicting sections (Example, Arguments Table, Performance).
- Retained `--log-dir` and `--preserve-source` arguments and their functionality in `cli.py`.
- Ensured file handling logic uses correct file suffixes and respects `--preserve-source`.
- **Fixes:**
- Resolved syntax errors in `cli.py` introduced by merge conflict markers.
- Applied minor code formatting and comment cleanup.
DhruvSrikanth
requested changes
Apr 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces user authentication to the Weco API, allowing users to create accounts and associate optimization sessions with their accounts. It enhances security and enables personalized experiences.
Motivation:
Previously, all sessions were anonymous. This change adds a layer of user management, enabling:
Changes Made:
/v1/authfor user registration (/signup), login (/token), and potentially retrieving user info.get_current_user_id) to extract the user ID from valid JWT tokens in request headers.POST /v1/sessions/(create_session) to associate the new session with the authenticated user's ID, if available.POST /v1/sessions/{session_id}/suggest(suggest_solution) andGET /v1/sessions/{session_id}(get_session_status) to verify that if a session has auser_id, the requesting user (identified via token) matches the session owner. Unauthorized access attempts result in a 403 Forbidden error.sessionstable now includes a nullableuser_idcolumn (likely a UUID referencing theauth.userstable).Testing:
Notes: