File size: 898 Bytes
71cf8f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | diff --git a/task_module.py b/task_module.py
new file mode 100644
index 0000000..0000001
--- /dev/null
+++ b/task_module.py
@@ -0,0 +1,20 @@
+from graphene import Scalar
+from base64 import b64encode, b64decode
+
+class SecureToken(Scalar):
+ @staticmethod
+ def serialize(value):
+ if not isinstance(value, (str, bytes)):
+ raise TypeError("SecureToken expects string or bytes")
+ value = value if isinstance(value, bytes) else value.encode("utf-8")
+ encoded = b64encode(value).decode("utf-8")
+ return f"tok_{encoded}"
+
+ @staticmethod
+ def parse_value(value):
+ if not isinstance(value, str):
+ raise TypeError("SecureToken expects string")
+ if not value.startswith("tok_"):
+ raise ValueError("Invalid prefix")
+ encoded = value[4:]
+ return b64decode(encoded)
\ No newline at end of file
|