Skip to main content

Default template for PDM package

Project description

FastAPI Social Service

Python FastAPI Pydantic PostgreSQL PostgreSQL

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.

Google

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
    

Github

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
    

Facebook

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
    

fibit

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
    

gitlab

**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
    

line

**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
    

linkedin

**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
    

notion

**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
    

twitter

**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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

social_auth_fastapi-0.1.6.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

social_auth_fastapi-0.1.6-py3-none-any.whl (75.2 kB view details)

Uploaded Python 3

File details

Details for the file social_auth_fastapi-0.1.6.tar.gz.

File metadata

  • Download URL: social_auth_fastapi-0.1.6.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.17.1 CPython/3.8.3 Linux/5.15.0-117-generic

File hashes

Hashes for social_auth_fastapi-0.1.6.tar.gz
Algorithm Hash digest
SHA256 83053ca011e2921b6ebb5b5887d5e1adda6709b91d591642da02e33e162d3e28
MD5 d3fa7433cb6174d2e8d9f6381faa93be
BLAKE2b-256 7897c1f41abb5b544662db228b36f57c4f8204c59a224f722ea227d80c0e9946

See more details on using hashes here.

File details

Details for the file social_auth_fastapi-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for social_auth_fastapi-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 29413397143dd381a8ed82ca7599dd8819b51e5b6867cedbb2945150ac099923
MD5 43e0753ddd4c30fe1da814aa09411f13
BLAKE2b-256 7a55a15a73c23d3a6fd545f192a798060e66d5bb1d3e2cba1e65217b259b2d54

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page