-
Notifications
You must be signed in to change notification settings - Fork 22
Add list sessions and revoke session methods and tests #483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR adds User Management Sessions APIs to the WorkOS Python SDK with two new methods: list_sessions (user-scoped session listing) and revoke_session (session revocation).
Key Changes:
- New
SessionPydantic model with proper typing for all session attributes (id,user_id,organization_id,status,auth_method,ip_address,user_agent,expires_at,ended_at, timestamps) list_sessionsmethod with full pagination support (limit, before, after, order) and auto-pagination viaWorkOSListResourcerevoke_sessionmethod using POST with JSON body{"session_id": "..."}- Both methods implemented for sync (
UserManagement) and async (AsyncUserManagement) clients - Comprehensive test coverage using
@pytest.mark.sync_and_asyncdecorator - Session model exported in public API (
workos/__init__.py)
Implementation Quality:
- Follows existing SDK patterns consistently (matches
list_auth_factorspattern exactly) - Proper type annotations throughout with Pydantic validation
- Includes
user_idinlist_argsfor correct auto-pagination behavior - Tests verify request path, query params, JSON body, and response parsing
- No breaking changes to existing APIs
Confidence Score: 5/5
- This PR is safe to merge with no identified issues
- The implementation precisely follows established SDK patterns, includes comprehensive test coverage, maintains type safety throughout, and introduces no breaking changes. All code mirrors existing similar features (especially
list_auth_factors), demonstrating consistency with the codebase architecture. - No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| workos/types/user_management/session.py | 5/5 | Added new Session model with proper Pydantic typing, following existing SDK patterns |
| workos/user_management.py | 5/5 | Implemented list_sessions and revoke_session methods for both sync and async clients, following existing patterns |
| tests/test_user_management_list_sessions.py | 5/5 | Comprehensive tests for list_sessions including query params, parsing, and auto-pagination |
| tests/test_user_management_revoke_session.py | 5/5 | Complete test coverage for revoke_session verifying POST request, JSON body, and response parsing |
Sequence Diagram
sequenceDiagram
participant Client
participant UserManagement
participant HTTPClient
participant WorkOSAPI
Note over Client,WorkOSAPI: List Sessions Flow
Client->>UserManagement: list_sessions(user_id="user_123", limit=10)
UserManagement->>UserManagement: Build params with limit, before, after, order
UserManagement->>HTTPClient: request(GET, /user_management/users/{user_id}/sessions, params)
HTTPClient->>WorkOSAPI: GET /user_management/users/user_123/sessions?limit=10
WorkOSAPI-->>HTTPClient: Response with session list + metadata
HTTPClient-->>UserManagement: Parse response
UserManagement->>UserManagement: Create SessionsListResource with list_args (includes user_id)
UserManagement-->>Client: Return SessionsListResource (supports auto-pagination)
Note over Client,WorkOSAPI: Revoke Session Flow
Client->>UserManagement: revoke_session(session_id="session_abc")
UserManagement->>UserManagement: Build JSON payload {"session_id": "session_abc"}
UserManagement->>HTTPClient: request(POST, /user_management/sessions/revoke, json)
HTTPClient->>WorkOSAPI: POST /user_management/sessions/revoke
WorkOSAPI-->>HTTPClient: Response with revoked Session object
HTTPClient-->>UserManagement: Parse response
UserManagement->>UserManagement: Validate as Session model
UserManagement-->>Client: Return Session with status="revoked"
8 files reviewed, no comments
…thods like list_users, list_invitations, and list_auth_factors
mattgd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks for adding!
Description
Adds User Management Sessions APIs to the WorkOS Python SDK, following existing patterns (typed models, RequestHelper, WorkOSListResource pagination, sync/async clients), without breaking changes.
What’s included
Pagination behavior
Tests
Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.