thejagstudio commited on
Commit
06ff3fd
·
verified ·
1 Parent(s): c08a2b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
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
- print(workos.api_key,workos.client_id)
 
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
- # Note: WorkOS Python SDK ListSessions usage might vary by version;
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
- workos.user_management.revoke_session(session.id)
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 = workos.user_management.list_sessions(user_id=user_id)
121
 
122
  # Revoke all
123
  for session in sessions_list.data:
124
- workos.user_management.revoke_session(session.id)
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