import json from typing import List from fastapi import Depends from fastapi import APIRouter from fastapi.security import OAuth2PasswordRequestForm from app import schemas from app.utils.utils import encode_base64 from utils.sx_time import sxtimeit from utils.sx_web import web_try from configs.settings import config super_admin_role = config.get('PERMISSIONS', 'super_admin_role') special_project_id = config.get('PERMISSIONS', 'special_project_id') router = APIRouter( prefix="/jpt/auth", tags=["auth-接口文档生成token"], ) @router.post("/switch") @web_try() @sxtimeit def switch_project(switch: schemas.SwitchProject): if switch.project_id == special_project_id and super_admin_role in switch.role_ids: return {"role_id": '726a51e45b4d11edbb4809c4df301a'} elif switch.project_id == special_project_id: return {"role_id": '9ff183445b4d11ed87db29f50d093a'} else: return {"role_id": '026bd8bc5b4e11ed857e6b5ec5c8d6'} @router.post("/login",response_model=schemas.Token) async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()): user_id, project_id = form_data.username, form_data.password token_data = {"user_id": user_id,"project_id": project_id, "role_id": "726a51e45b4d11edbb4809c4df301a"} token_data_str =json.dumps(token_data) access_token = encode_base64(token_data_str).replace('\n','') return {"access_token": access_token, "token_type": "bearer"}