XThomasBU commited on
Commit
2cc5127
·
verified ·
1 Parent(s): 2805c45

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +35 -0
main.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chainlit as cl
2
+ import base64
3
+ import json
4
+
5
+ @cl.header_auth_callback
6
+ def header_auth_callback(headers: dict) -> Optional[cl.User]:
7
+
8
+ print("\n\n\nI am here\n\n\n")
9
+ # try: # TODO: Add try-except block after testing
10
+ # TODO: Implement to get the user information from the headers (not the cookie)
11
+ cookie = headers.get("cookie") # gets back a str
12
+ # Create a dictionary from the pairs
13
+ cookie_dict = {}
14
+ for pair in cookie.split("; "):
15
+ key, value = pair.split("=", 1)
16
+ # Strip surrounding quotes if present
17
+ cookie_dict[key] = value.strip('"')
18
+
19
+ decoded_user_info = base64.b64decode(
20
+ cookie_dict.get("X-User-Info", "")
21
+ ).decode()
22
+ decoded_user_info = json.loads(decoded_user_info)
23
+
24
+ return cl.User(
25
+ identifier=decoded_user_info["email"],
26
+ metadata={
27
+ "name": decoded_user_info["name"],
28
+ "avatar": decoded_user_info["profile_image"],
29
+ },
30
+ )
31
+
32
+ @cl.on_chat_start
33
+ async def start():
34
+ await cl.Message(content = "HELLO").send()
35
+