Generate token with username/password
This commit is contained in:
7
main.py
7
main.py
@@ -70,6 +70,8 @@ async def global_auth(request: Request):
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
access_tokens = []
|
||||
|
||||
def generate_access_token(username: str, password: str) -> str:
|
||||
"""
|
||||
根据用户名和密码生成JWT access token
|
||||
@@ -100,7 +102,10 @@ def generate_access_token(username: str, password: str) -> str:
|
||||
}
|
||||
|
||||
# 生成并返回JWT token
|
||||
return jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM)
|
||||
token = jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM)
|
||||
access_tokens.append(token)
|
||||
|
||||
return token
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user