smgc commited on
Commit
62a814c
1 Parent(s): fed49ba

Update helper.py

Browse files
Files changed (1) hide show
  1. helper.py +14 -22
helper.py CHANGED
@@ -1,34 +1,28 @@
1
  import jwt
2
  import uuid
3
  from datetime import datetime, timedelta
4
- import random
5
- import string
6
- import os
7
-
8
- def generate_random_tuple():
9
- """
10
- Generate a random tuple containing a string and an integer.
11
- Returns:
12
- tuple: A tuple containing:
13
- - str: A random string of length 6-12 consisting of ASCII letters and digits.
14
- - int: A random 6-digit integer between 100000 and 999999.
15
- """
16
- # Generate a random string of length 6-12
17
- random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=random.randint(6, 12)))
18
-
19
- # Generate a random 6-digit integer
20
- random_int = random.randint(100000, 999999)
21
-
22
- return (random_string, random_int)
23
 
24
  def create_jwt(github_user_login: str, user_id: int) -> str:
25
  """
26
  Create a JSON Web Token (JWT) for a given GitHub user.
 
27
  Args:
28
  github_user_login (str): The GitHub username of the user.
29
  user_id (int): The user's ID.
 
30
  Returns:
31
  str: A JWT encoded string containing user information and authentication details.
 
 
 
 
 
 
 
 
 
 
 
32
  """
33
  LLM_TOKEN_LIFETIME = timedelta(hours=1)
34
  now = datetime.utcnow()
@@ -44,6 +38,4 @@ def create_jwt(github_user_login: str, user_id: int) -> str:
44
  "plan": "Free"
45
  }
46
 
47
- # 使用环境变量获取密钥,如果没有设置,则使用默认值
48
- secret_key = os.environ.get('JWT_SECRET_KEY', 'llm-secret')
49
- return jwt.encode(payload, secret_key, algorithm='HS256')
 
1
  import jwt
2
  import uuid
3
  from datetime import datetime, timedelta
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def create_jwt(github_user_login: str, user_id: int) -> str:
6
  """
7
  Create a JSON Web Token (JWT) for a given GitHub user.
8
+
9
  Args:
10
  github_user_login (str): The GitHub username of the user.
11
  user_id (int): The user's ID.
12
+
13
  Returns:
14
  str: A JWT encoded string containing user information and authentication details.
15
+
16
+ Note:
17
+ The token has a lifetime of 1 hour and includes the following claims:
18
+ - iat: Issued at time
19
+ - exp: Expiration time
20
+ - jti: Unique token identifier
21
+ - userId: User's ID
22
+ - githubUserLogin: GitHub username
23
+ - isStaff: Boolean indicating staff status (default: False)
24
+ - hasLlmClosedBetaFeatureFlag: Boolean for LLM closed beta feature (default: False)
25
+ - plan: User's plan (default: "Free")
26
  """
27
  LLM_TOKEN_LIFETIME = timedelta(hours=1)
28
  now = datetime.utcnow()
 
38
  "plan": "Free"
39
  }
40
 
41
+ return jwt.encode(payload, 'llm-secret', algorithm='HS256')