Fastapi密码授权相关
主要实现获取token,前端携带token请求
"""
密码授权相关
"""
from fastapi import APIRouter, Depends, Header, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from pydantic import BaseModel
from passlib.context import CryptContext
from typing import List, Optional
from datetime import datetime, timedelta
import jwt
auth_app = APIRouter()
# JWT 配置 密钥
SECRET_KEY = "Model"
# 加密算法
ALGORITHM = "HS256"
# token失效时间
ACCESS_TOKEN_EXPIRE_MINUTES = 30
# 密码哈希配置
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
# OAuth2 配置
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
hashed_password = pwd_context.hash('123456')
print(hashed_password)
# 定义数据
fake_users_db = {
"haha": {
"username": "haha",
"password": 123456,
"hashed_password": hashed_password,
"disabled": False
},
"james":

最低0.47元/天 解锁文章
1016

被折叠的 条评论
为什么被折叠?



