mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2026-03-13 09:31:31 +08:00
* Add user social binding and unbinding * Add oauth2 state to binding * Update oauth2 state * Fix imports * Update some interface definitions * Update the authorization type security
28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
from fastapi import APIRouter, Request
|
|
|
|
from backend.common.response.response_schema import ResponseModel, ResponseSchemaModel, response_base
|
|
from backend.common.security.jwt import DependsJwtAuth
|
|
from backend.database.db import CurrentSession, CurrentSessionTransaction
|
|
from backend.plugin.oauth2.enums import UserSocialType
|
|
from backend.plugin.oauth2.service.user_social_service import user_social_service
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get('/me/bindings', summary='获取用户已绑定的社交账号', dependencies=[DependsJwtAuth])
|
|
async def get_user_bindings(db: CurrentSession, request: Request) -> ResponseSchemaModel[list[str]]:
|
|
bindings = await user_social_service.get_bindings(db=db, user_id=request.user.id)
|
|
return response_base.success(data=bindings)
|
|
|
|
|
|
@router.get('/me/binding', summary='获取绑定授权链接', dependencies=[DependsJwtAuth])
|
|
async def get_binding_auth_url(request: Request, source: UserSocialType) -> ResponseSchemaModel[str]:
|
|
binding_url = await user_social_service.get_binding_auth_url(user_id=request.user.id, source=source)
|
|
return response_base.success(data=binding_url)
|
|
|
|
|
|
@router.delete('/me/unbinding', summary='解绑用户社交账号', dependencies=[DependsJwtAuth])
|
|
async def unbinding_user(db: CurrentSessionTransaction, request: Request, source: UserSocialType) -> ResponseModel:
|
|
await user_social_service.unbinding(db=db, user_id=request.user.id, source=source)
|
|
return response_base.success()
|