Fix API token expiration and org member getOrganization access - #29
Conversation
Access tokens with a positive lifetime are now rejected after expiration during auth and token resolution. Organization members (not only admins) can call getOrganization via the account organizations endpoint. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
📝 WalkthroughWalkthroughAdds a token expiration check ( ChangesAccess token expiry and org authorization
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthDependency as get_current_user/get_org_id_from_token
participant TokenStore as access_tokens collection
Client->>AuthDependency: Request with API token
AuthDependency->>TokenStore: Fetch stored_token
AuthDependency->>AuthDependency: is_access_token_expired(stored_token)
AuthDependency-->>Client: 401 "API token expired" (if expired)
AuthDependency-->>Client: Proceed with request (if not expired)
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/python/app/auth.py`:
- Line 4: The import in auth.py is using datetime.UTC, which is not compatible
with the declared Python 3.9/3.10 support. Update the auth module to use
timezone.utc instead, and make the same timezone import/value change in the
matching tests that reference this constant so the code imports and runs
correctly on all supported versions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ac0e1d23-271b-4e6c-a822-5ff7435431fa
📒 Files selected for processing (4)
packages/python/app/auth.pypackages/python/app/routes/orgs.pypackages/python/tests/test_access_tokens.pypackages/python/tests/test_org_permissions.py
| # Standard library imports | ||
| import os | ||
| import logging | ||
| from datetime import UTC, datetime, timedelta |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check declared Python version constraints
fd -a pyproject.toml packages/python | xargs -I{} sh -c 'echo "== {} =="; rg -n "requires-python|python_requires|target-version" {}'
fd -a '.python-version|.tool-versions' 2>/dev/null | xargs -I{} sh -c 'echo "== {} =="; cat {}'
rg -n "python" packages/python/setup.cfg packages/python/setup.py 2>/dev/null | rg -i "version|require"Repository: analytiq-hub/doc-router
Length of output: 364
Use timezone.utc for Python 3.9/3.10 compatibility
packages/python/pyproject.toml declares requires-python = ">=3.9", but datetime.UTC is only available in Python 3.11+. This will fail at import time on supported runtimes; switch to timezone.utc here and in the matching tests.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/python/app/auth.py` at line 4, The import in auth.py is using
datetime.UTC, which is not compatible with the declared Python 3.9/3.10 support.
Update the auth module to use timezone.utc instead, and make the same timezone
import/value change in the matching tests that reference this constant so the
code imports and runs correctly on all supported versions.
Summary
lifetimeduring authentication: tokens pastcreated_at + lifetimedays are rejected with 401 (API token expired).lifetimeof 0 still means no expiration.GET /v0/account/organizations?organization_id=…(fixesgetOrganization()403 for regular members).Test plan
pytest packages/python/tests/test_access_tokens.py— includes newtest_expired_access_token_rejectedpytest packages/python/tests/test_org_permissions.py— includes newtest_org_member_can_get_organization_by_iddefault_prompt_enabled) without console 403Made with Cursor
Summary by CodeRabbit