Fastapi密码授权相关

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": 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BRYTLEVSON

打赏的都是天使,创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值