Skip to content

Commit f33b90c

Browse files
Extract feature flags (#480)
Co-authored-by: Kendall Strautman Swarthout <36613477+kendallstrautman@users.noreply.github.com>
1 parent b5c3db7 commit f33b90c

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

tests/test_session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def session_constants(self):
5151
"roles": ["admin"],
5252
"permissions": ["read"],
5353
"entitlements": ["feature_1"],
54+
"feature_flags": ["flag1", "flag2"],
5455
"exp": int(current_datetime.timestamp()) + 3600,
5556
"iat": int(current_datetime.timestamp()),
5657
}
@@ -244,6 +245,7 @@ def test_authenticate_success(self, session_constants, mock_user_management):
244245
"roles": ["admin"],
245246
"permissions": ["read"],
246247
"entitlements": ["feature_1"],
248+
"feature_flags": ["flag1", "flag2"],
247249
}
248250

249251
with patch.object(Session, "unseal_data", return_value=mock_session), patch(
@@ -263,6 +265,7 @@ def test_authenticate_success(self, session_constants, mock_user_management):
263265
assert response.roles == ["admin"]
264266
assert response.permissions == ["read"]
265267
assert response.entitlements == ["feature_1"]
268+
assert response.feature_flags == ["flag1", "flag2"]
266269
assert response.user.id == session_constants["USER_ID"]
267270
assert response.impersonator is None
268271

@@ -312,6 +315,7 @@ def test_authenticate_success_with_roles(
312315
"roles": ["admin", "member"],
313316
"permissions": ["read", "write"],
314317
"entitlements": ["feature_1"],
318+
"feature_flags": ["flag1", "flag2"],
315319
}
316320

317321
with patch.object(Session, "unseal_data", return_value=mock_session), patch(
@@ -331,6 +335,7 @@ def test_authenticate_success_with_roles(
331335
assert response.roles == ["admin", "member"]
332336
assert response.permissions == ["read", "write"]
333337
assert response.entitlements == ["feature_1"]
338+
assert response.feature_flags == ["flag1", "flag2"]
334339
assert response.user.id == session_constants["USER_ID"]
335340
assert response.impersonator is None
336341

@@ -410,6 +415,7 @@ def test_refresh_success(self, session_constants, mock_user_management):
410415
"roles": ["admin"],
411416
"permissions": ["read"],
412417
"entitlements": ["feature_1"],
418+
"feature_flags": ["flag1", "flag2"],
413419
},
414420
):
415421
response = session.refresh()
@@ -511,6 +517,7 @@ async def test_refresh_success(self, session_constants, mock_user_management):
511517
"roles": ["admin"],
512518
"permissions": ["read"],
513519
"entitlements": ["feature_1"],
520+
"feature_flags": ["flag1", "flag2"],
514521
},
515522
):
516523
response = await session.refresh()

workos/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from functools import lru_cache
55
import json
66
from typing import Any, Dict, Optional, Union, cast
7+
78
import jwt
89
from jwt import PyJWKClient
910
from cryptography.fernet import Fernet
@@ -107,6 +108,7 @@ def authenticate(
107108
entitlements=decoded.get("entitlements", None),
108109
user=session["user"],
109110
impersonator=session.get("impersonator", None),
111+
feature_flags=decoded.get("feature_flags", None),
110112
)
111113

112114
def refresh(
@@ -235,6 +237,7 @@ def refresh(
235237
entitlements=decoded.get("entitlements", None),
236238
user=auth_response.user,
237239
impersonator=auth_response.impersonator,
240+
feature_flags=decoded.get("feature_flags", None),
238241
)
239242
except Exception as e:
240243
return RefreshWithSessionCookieErrorResponse(
@@ -326,6 +329,7 @@ async def refresh(
326329
entitlements=decoded.get("entitlements", None),
327330
user=auth_response.user,
328331
impersonator=auth_response.impersonator,
332+
feature_flags=decoded.get("feature_flags", None),
329333
)
330334
except Exception as e:
331335
return RefreshWithSessionCookieErrorResponse(

workos/types/user_management/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class AuthenticateWithSessionCookieSuccessResponse(WorkOSModel):
2424
user: User
2525
impersonator: Optional[Impersonator] = None
2626
entitlements: Optional[Sequence[str]] = None
27+
feature_flags: Optional[Sequence[str]] = None
2728

2829

2930
class AuthenticateWithSessionCookieErrorResponse(WorkOSModel):

0 commit comments

Comments
 (0)