Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,7 +52,8 @@ from workos import WorkOSClient
|
|
| 52 |
# For now we will check if they exist, otherwise these endpoints will fail gracefully or you can hardcode for testing if needed
|
| 53 |
workos.api_key = os.environ.get('WORKOS_API_KEY', 'placeholder_key')
|
| 54 |
workos.client_id = os.environ.get('WORKOS_CLIENT_ID', 'placeholder_id')
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
@app.route('/auth/verify-session', methods=['POST'])
|
| 58 |
def verify_session():
|
|
@@ -69,15 +70,8 @@ def verify_session():
|
|
| 69 |
|
| 70 |
try:
|
| 71 |
# 1. List all active sessions for the user
|
| 72 |
-
|
| 73 |
-
# checking User Management > List Sessions or similar via SDK.
|
| 74 |
-
# As of recent versions, it's workos.user_management.list_sessions(user_id=...)
|
| 75 |
-
# or verify standard usage. We'll use the generic client resources if specific helper isn't found,
|
| 76 |
-
# but workos.user_management is the standard path.
|
| 77 |
-
|
| 78 |
-
sessions_list = workos.user_management.list_sessions(
|
| 79 |
user_id=user_id,
|
| 80 |
-
type='user_session' # Ensure we get user sessions
|
| 81 |
)
|
| 82 |
|
| 83 |
active_sessions = sessions_list.data
|
|
@@ -87,7 +81,7 @@ def verify_session():
|
|
| 87 |
for session in active_sessions:
|
| 88 |
if session.id != current_session_id:
|
| 89 |
# Revoke this old/extra session
|
| 90 |
-
|
| 91 |
revoked_count += 1
|
| 92 |
|
| 93 |
return jsonify({
|
|
@@ -117,11 +111,11 @@ def logout_everywhere():
|
|
| 117 |
|
| 118 |
try:
|
| 119 |
# List all sessions
|
| 120 |
-
sessions_list =
|
| 121 |
|
| 122 |
# Revoke all
|
| 123 |
for session in sessions_list.data:
|
| 124 |
-
|
| 125 |
|
| 126 |
return jsonify({'status': 'success', 'message': 'All sessions revoked.'})
|
| 127 |
|
|
|
|
| 52 |
# For now we will check if they exist, otherwise these endpoints will fail gracefully or you can hardcode for testing if needed
|
| 53 |
workos.api_key = os.environ.get('WORKOS_API_KEY', 'placeholder_key')
|
| 54 |
workos.client_id = os.environ.get('WORKOS_CLIENT_ID', 'placeholder_id')
|
| 55 |
+
|
| 56 |
+
workos_client = WorkOSClient(api_key=workos.api_key, client_id=workos.client_id)
|
| 57 |
|
| 58 |
@app.route('/auth/verify-session', methods=['POST'])
|
| 59 |
def verify_session():
|
|
|
|
| 70 |
|
| 71 |
try:
|
| 72 |
# 1. List all active sessions for the user
|
| 73 |
+
sessions_list = workos_client.user_management.list_sessions(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
user_id=user_id,
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
active_sessions = sessions_list.data
|
|
|
|
| 81 |
for session in active_sessions:
|
| 82 |
if session.id != current_session_id:
|
| 83 |
# Revoke this old/extra session
|
| 84 |
+
workos_client.user_management.revoke_session(session.id)
|
| 85 |
revoked_count += 1
|
| 86 |
|
| 87 |
return jsonify({
|
|
|
|
| 111 |
|
| 112 |
try:
|
| 113 |
# List all sessions
|
| 114 |
+
sessions_list = workos_client.user_management.list_sessions(user_id=user_id)
|
| 115 |
|
| 116 |
# Revoke all
|
| 117 |
for session in sessions_list.data:
|
| 118 |
+
workos_client.user_management.revoke_session(session.id)
|
| 119 |
|
| 120 |
return jsonify({'status': 'success', 'message': 'All sessions revoked.'})
|
| 121 |
|