-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adds session helpers #384
Adds session helpers #384
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.
Thanks for adding! Left a bunch of comments inline, but most are minor.
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! There's still two outstanding comments regarding List vs. Sequence in /types/user_management/session.py, but nothing new from second pass.
workos/session.py
Outdated
def is_valid_jwt(self, token: str) -> bool: | ||
try: | ||
signing_key = self.jwks.get_signing_key_from_jwt(token) | ||
jwt.decode(token, signing_key.key, algorithms=self.jwk_algorithms) | ||
return True | ||
except jwt.exceptions.InvalidTokenError: | ||
return False | ||
|
||
@staticmethod | ||
def seal_data(data: Dict[str, Any], key: str) -> str: | ||
fernet = Fernet(key) | ||
# Encrypt and convert bytes to string | ||
encrypted_bytes = fernet.encrypt(json.dumps(data).encode()) | ||
return encrypted_bytes.decode("utf-8") | ||
|
||
@staticmethod | ||
def unseal_data(sealed_data: str, key: str) -> Dict[str, Any]: | ||
fernet = Fernet(key) | ||
# Convert string back to bytes before decryption | ||
encrypted_bytes = sealed_data.encode("utf-8") | ||
decrypted_str = fernet.decrypt(encrypted_bytes).decode() | ||
return cast(Dict[str, Any], json.loads(decrypted_str)) |
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.
If these are all private, we may want to mark them with a _
prefix.
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.
They're not really private since they can still be accessed statically. Should we still add the prefix?
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.
Good question, up to you. "Private" is really just a suggestion anyway. It has no real encapsulation benefits in Python. is_valid_jwt
could at least use it though. More-so just helps us so we can consider these methods internal if we need to update.
Fixes #350
Description
Adds new session helpers. Example API:
Also makes it so dependencies are loaded from
requirements.txt
rather than hardcoded insetup.py
.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.