mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-17 22:21:35 +08:00

* [WIP] Add OAuth 2.0 authorization login * Add social user relationship table * Update social user relationship table back_populates * Add OAuth 2.0 related interface * Automatically redirect authorization addresses * Update OAuth2 authorization to GitHub * Add implementation code * fix the callback interface return * fix typo * fix the api return * fix imports * Fix logic for creating system users and social tables * Fix user information storage * Add OAuth2 source link * remove unnecessary db refresh * remove the front end docker-compose annotation
28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
from typing import Union
|
||
|
||
from sqlalchemy import ForeignKey, String
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from backend.app.models.base import Base, id_key
|
||
|
||
|
||
class UserSocial(Base):
|
||
"""用户社交表(OAuth2)"""
|
||
|
||
__tablename__ = 'sys_user_social'
|
||
|
||
id: Mapped[id_key] = mapped_column(init=False)
|
||
source: Mapped[str] = mapped_column(String(20), comment='第三方用户来源')
|
||
open_id: Mapped[str | None] = mapped_column(String(20), default=None, comment='第三方用户的 open id')
|
||
uid: Mapped[str | None] = mapped_column(String(20), default=None, comment='第三方用户的 ID')
|
||
union_id: Mapped[str | None] = mapped_column(String(20), default=None, comment='第三方用户的 union id')
|
||
scope: Mapped[str | None] = mapped_column(String(120), default=None, comment='第三方用户授予的权限')
|
||
code: Mapped[str | None] = mapped_column(String(50), default=None, comment='用户的授权 code')
|
||
# 用户 OAuth2 一对多
|
||
user_id: Mapped[int | None] = mapped_column(
|
||
ForeignKey('sys_user.id', ondelete='SET NULL'), default=None, comment='用户关联ID'
|
||
)
|
||
user: Mapped[Union['User', None]] = relationship(init=False, back_populates='socials') # noqa: F821
|