mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
* 🎨 修改 nonebot_bison 目录位置 * auto fix by pre-commit hooks * 🚚 fix frontend build target * 🚚 use soft link * Revert "🚚 use soft link" This reverts commit de21f79d5ae1bd5515b04f42a4138cb25ddf3e62. * 🚚 modify dockerfile --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: felinae98 <731499577@qq.com>
24 lines
505 B
Python
24 lines
505 B
Python
import datetime
|
|
import random
|
|
import string
|
|
from typing import Optional
|
|
|
|
import jwt
|
|
|
|
_key = "".join(random.SystemRandom().choice(string.ascii_letters) for _ in range(16))
|
|
|
|
|
|
def pack_jwt(obj: dict) -> str:
|
|
return jwt.encode(
|
|
{"exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1), **obj},
|
|
_key,
|
|
algorithm="HS256",
|
|
)
|
|
|
|
|
|
def load_jwt(token: str) -> Optional[dict]:
|
|
try:
|
|
return jwt.decode(token, _key, algorithms=["HS256"])
|
|
except:
|
|
return None
|