Default template for PDM package
Project description
FastAPI Social Service
0. Technology Stack and Features
-
⚡ FastAPI for the Python backend API.
-
🧰 SQLModel for the Python SQL database interactions (ORM).
-
🔍 Pydantic, used by FastAPI, for the data validation and settings management.
-
💾 PostgreSQL as the SQL database.
-
💾 MySQL as the SQL database.
-
🔒 Secure password hashing by default.
-
🔑 JWT token authentication.
-
📫 Email based password recovery.
-
🎨 PDM is a modern Python package and dependency manager supporting the latest PEP standards.
1. Prerequisites
1.0 Start
Clone repository
git clone https://github.com/congpc130599/social-auth
Environment Variables (.env)
Then create a .env
file in the project
directory.
Configure ENV Google:
-
Create GOOGLE_CLIENT_ID , GOOGLE_CLIENT_SECRET.
-
Setting in file env
GOOGLE_CLIENT_ID = my_client_id GOOGLE_CLIENT_SECRET = my_client_secret
Configure ENV Github:
-
Create GITHUB_CLIENT_ID , GITHUB_CLIENT_SECRET.
-
Setting in file env
GITHUB_CLIENT_ID = my_client_id GITHUB_CLIENT_SECRET = my_client_secret
Configure ENV Facebook:
-
Create FACEBOOK_CLIENT_ID , FACEBOOK_CLIENT_SECRET.
-
Setting in file env
FACEBOOK_CLIENT_ID = my_client_id FACEBOOK_CLIENT_SECRET = my_client_secret
Configure ENV Fibit:
-
Create FIBIT_CLIENT_ID , FIBIT_CLIENT_SECRET.
-
Setting in file env
FIBIT_CLIENT_ID = my_client_id FIBIT_CLIENT_SECRET = my_client_secret
**Configure ENV GitLab:**
-
Create GITLAB_CLIENT_ID , GITLAB_CLIENT_SECRET, GITLAB_BASE_ENDPOINT_URL.
-
Setting in file env
GITLAB_CLIENT_ID = my_client_id GITLAB_CLIENT_SECRET = my_client_secret GITLAB_BASE_ENDPOINT_URL = url
**Configure ENV Line:**
-
Create LINE_CLIENT_ID , LINE_CLIENT_SECRET.
-
Setting in file env
LINE_CLIENT_ID = my_client_id LINE_CLIENT_SECRET = my_client_secret
**Configure ENV Linkedin:**
-
Create LINKEDIN_CLIENT_ID , LINKEDIN_CLIENT_SECRET.
-
Setting in file env
LINKEDIN_CLIENT_ID = my_client_id LINKEDIN_CLIENT_SECRET = my_client_secret
**Configure ENV Notion:**
-
Create LINKEDIN_CLIENT_ID , LINKEDIN_CLIENT_SECRET.
-
Setting in file env
NOTION_CLIENT_ID = my_client_id NOTION_CLIENT_SECRET = my_client_secret
**Configure ENV Twitter:**
-
Create TWITTER_CLIENT_ID , TWITTER_CLIENT_SECRET.
-
Setting in file env
TWITTER_CLIENT_ID = my_client_id TWITTER_CLIENT_SECRET = my_client_secret
Integration
Create user model
#!/usr/bin/env python3
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
from social_auth_fastapi.models.base import DataClassBase
class Account(DataClassBase):
"""User table"""
__tablename__ = 't_account'
id: Mapped[int] = mapped_column(primary_key=True, index=True, autoincrement=True, sort_order=-999,
comment='Primary key id')
name: Mapped[str] = mapped_column(String(255), comment='name')
email: Mapped[str] = mapped_column(String(255), comment='email')
For integrating the package into an existing FastAPI application
from fastapi import FastAPI
from contextlib import asynccontextmanager
app = FastAPI(lifespan=register_init)
@asynccontextmanager
async def register_init(app: FastAPI):
"""
Start initialization
:return:
"""
await register_auth_social_init(
app,
user_model=Account, # model auth
sqlalchemy_database_uri=settings.SQLALCHEMY_DATABASE_URI,
google_client_id=settings.GOOGLE_CLIENT_ID,
github_client_secret=settings.GOOGLE_CLIENT_SECRET,
# ...
)
yield
Install using pdm
curl -sSL https://pdm-project.org/install-pdm.py | python3 -
pdm python install 3.11.7
pdm install
Scripts
pdm dev
: Run server
Ensuring it ran without any problem.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
File details
Details for the file
social_auth_fastapi-0.1.6.tar.gz
.File metadata
File hashes
83053ca011e2921b6ebb5b5887d5e1adda6709b91d591642da02e33e162d3e28
d3fa7433cb6174d2e8d9f6381faa93be
7897c1f41abb5b544662db228b36f57c4f8204c59a224f722ea227d80c0e9946
See more details on using hashes here.