現代のアプリユーザーは、新しいパスワードを作ることを望んでいません。その解決策が SSO(シングルサインオン) です。
この記事では、FastAPI, MongoDB, JWT, そして fastapi-sso
ライブラリを使って、Google アカウントでログイン可能な SSO を構築する方法をステップ・バイ・ステップで解説します。
Continue reading "FastAPI で Google OAuth を使った Single Sign-On (SSO) を実装する方法"
現代のアプリユーザーは、新しいパスワードを作ることを望んでいません。その解決策が SSO(シングルサインオン) です。
この記事では、FastAPI, MongoDB, JWT, そして fastapi-sso
ライブラリを使って、Google アカウントでログイン可能な SSO を構築する方法をステップ・バイ・ステップで解説します。
Continue reading "FastAPI で Google OAuth を使った Single Sign-On (SSO) を実装する方法"
ในยุคที่ผู้ใช้งานไม่อยากจดจำรหัสผ่านอีกต่อไป — Single Sign-On (SSO) คือคำตอบ
บทความนี้จะแนะนำวิธีสร้างระบบล็อกอินผ่านบัญชี Google บนแอปพลิเคชัน FastAPI โดยใช้ MongoDB, JWT, และไลบรารี fastapi-sso
เพื่อให้คุณเริ่มต้นได้อย่างมั่นใจและปลอดภัย
Continue reading "วิธีเชื่อมต่อระบบ Single Sign-On (SSO) ด้วย Google OAuth ใน FastAPI"
Do your users really need another password to remember?
In modern web applications, Single Sign-On (SSO) is a must-have. It provides a seamless and secure authentication experience—allowing users to log in using trusted identity providers like Google, Microsoft, or Facebook.
In this guide, we’ll show you how to implement Google SSO using FastAPI, MongoDB, and JWT—in just a few steps.
Managing passwords is painful—for users and developers. That’s where SSO comes in.
Here’s why modern apps need SSO:
Tool | Purpose |
---|---|
FastAPI | Python web framework |
fastapi-sso | SSO integration with Google OAuth2 |
MongoDB + Motor | Store user records |
python-jose | Generate and verify JWT tokens |
passlib | Hash passwords (for fallback login) |
pip install fastapi uvicorn motor fastapi-sso python-dotenv python-jose passlib[bcrypt]
http://localhost:8000/api/auth/google/callback
.env
Create a .env
file in your project root:
MONGODB_URI=mongodb://localhost:27017
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URL=http://localhost:8000/api/auth/google/callback
JWT_SECRET=your_jwt_secret
See the full code here in our GitHub example, or build it using this structure:
# /api/auth/google/login → Redirects to Google
# /api/auth/google/callback → Handles user data, issues JWT
# /api/register → Optional manual registration
# /api/token → Password login
# JWT used for all access control
✅ Google login issues JWT for API access
✅ MongoDB stores new users only once
✅ FastAPI protects routes using the JWT token
sequenceDiagram
actor User
participant Browser
participant FastAPI
participant GoogleOAuth
participant MongoDB
User->>Browser: Click "Login with Google"
Browser->>FastAPI: GET /auth/google/login
FastAPI->>GoogleOAuth: Redirect to Google OAuth URL
User->>GoogleOAuth: Login & Consent
GoogleOAuth->>FastAPI: Redirect to /auth/google/callback?code=XYZ
FastAPI->>GoogleOAuth: Verify & fetch profile
GoogleOAuth-->>FastAPI: Return user info (email, name, avatar)
alt New User
FastAPI->>MongoDB: Insert user profile
else Existing User
FastAPI->>MongoDB: Fetch user profile
end
FastAPI->>FastAPI: Generate JWT
FastAPI-->>Browser: Return access_token or redirect with token
Browser->>User: Authenticated!
When a new user logs in via Google, we store:
{
"_id": "ObjectId(...)",
"username": "jane.doe@gmail.com",
"email": "jane.doe@gmail.com",
"full_name": "Jane Doe",
"avatar_url": "https://lh3.googleusercontent.com/...",
"sso_provider": "google",
"created_at": "2025-07-02T08:00:00Z"
}
After login, users receive a token like this:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR...",
"token_type": "bearer"
}
Use it in headers:
Authorization: Bearer <token>
Protect any route in FastAPI:
@router.get("/me")
async def me(current_user=Depends(get_current_user)):
return current_user
You just learned how to:
fastapi-sso
This pattern scales well and forms the backbone of secure, modern user authentication.
Simplico Co., Ltd. helps startups and enterprises build fast, secure, and scalable backend systems using FastAPI, MongoDB, and cloud-native technologies.
Let’s bring your product to life—with speed and confidence.
🌐 Visit us at simplico.net
配車サービス市場は急速に成長しています。とはいえ、独自のタクシープラットフォームを立ち上げることは、もはや複雑で高額なプロジェクトではありません。
Simplico Co., Ltd. は、起業家、運輸会社、スマートシティ関連の組織向けに、完全な配車システムを開発・提供しています。
貴社ブランドに対応可能で、安全性・拡張性に優れ、すぐにサービスを開始できる構成です。
Continue reading "Simplicoで始めるタクシー配車アプリ開発:スケーラブル、安全、即スタート可能!"
อุตสาหกรรมบริการรถโดยสารกำลังเติบโตอย่างรวดเร็ว แต่การเปิดตัวแพลตฟอร์มจองแท็กซี่ของคุณเองไม่จำเป็นต้องซับซ้อนหรือมีค่าใช้จ่ายสูงอีกต่อไป
ที่ Simplico Co., Ltd. เราช่วยผู้ประกอบการ บริษัทขนส่ง และโครงการสมาร์ตซิตี้เปิดตัวระบบ จองแท็กซี่ครบวงจร — พร้อมแบรนด์ของคุณเอง ปลอดภัย และขยายได้ในอนาคต
Continue reading "สร้างแอปจองแท็กซี่ของคุณเองกับ Simplico: ปลอดภัย ขยายได้ และพร้อมเปิดตัวทันที"
The ride-hailing industry is growing rapidly, but launching your own taxi platform doesn’t need to be complex or expensive. At Simplico Co., Ltd., we help entrepreneurs, transport companies, and smart-city operators launch fully featured taxi booking systems—custom-branded, scalable, and secure.
Continue reading "Build Your Own Taxi Booking App with Simplico: Scalable, Secure & Ready to Launch"
電気自動車(EV)の普及に伴い、充電ステーションの効率的な管理と、ユーザーの利用履歴を確実に記録できるシステムの需要が高まっています。
Continue reading "拡張性のあるEV充電ステーション管理システムのバックエンド設計 — Simplicoによる開発"
ในยุคที่ยานยนต์ไฟฟ้า (EV) กำลังเติบโตอย่างรวดเร็ว การบริหารจัดการสถานีชาร์จอย่างมีประสิทธิภาพและสามารถตรวจสอบย้อนหลังได้ คือหัวใจสำคัญของความสำเร็จ
Continue reading "วางระบบ Backend สำหรับสถานีชาร์จ EV ที่พร้อมขยายตัว — ออกแบบโดย Simplico"
As electric mobility expands, so does the need for smart, reliable, and auditable charging infrastructure. At Simplico, we’ve designed an EV charging backend that serves both business goals and engineering needs — one that supports real-time OCPP communication, robust user management, session tracking, and future growth.
カスタム商品を販売しているなら、価格設定がすぐにややこしくなるって知ってますよね。
サイズ、素材、仕上げ、特急対応、あるいは単に「毎回オーダーが違う」ってだけでもう大混乱。