Skip to content

Repository files navigation

FastAPI + Gradio OAuth App

A web application that combines FastAPI with Gradio interface and Google OAuth authentication.

Features

  • 🔐 Google OAuth authentication
  • 🚀 FastAPI backend
  • 🎨 Gradio interface
  • 📱 Session management
  • 🔒 Secure configuration

Prerequisites

  • Python 3.8 or higher
  • Google Cloud Console account (for OAuth credentials)

Quick Start

Option 1: Interactive Setup (Recommended)

# Run the interactive OAuth setup
python setup_oauth.py

This will guide you through setting up your Google OAuth credentials and create the .env file automatically.

Option 2: Manual Setup

# Run the setup script
./setup.sh

This will:

  • Create a Python virtual environment
  • Install all dependencies
  • Create a .env file from template

3. Configure OAuth

Important: Follow the detailed guide in GOOGLE_OAUTH_SETUP.md for proper OAuth configuration.

Quick steps:

  1. Go to Google Cloud Console
  2. Create a new project or select existing one
  3. Enable Google+ API
  4. Create OAuth 2.0 credentials (Web application type)
  5. Set authorized redirect URI to: http://localhost:8000/auth
  6. Copy Client ID and Client Secret

4. Update Environment Variables

Edit the .env file:

# OAuth Configuration
GOOGLE_CLIENT_ID=your_actual_client_id
GOOGLE_CLIENT_SECRET=your_actual_client_secret

# Session Configuration
SECRET_KEY=your_long_random_secret_key

# Server Configuration
HOST=0.0.0.0
PORT=8000
DEBUG=True

5. Run the Application

# Start the server
./run.sh

The application will be available at: http://localhost:8000

Usage

  1. Homepage (/): Shows login link or user info if authenticated
  2. Login (/login): Redirects to Google OAuth
  3. Gradio Interface (/gradio): Interactive Gradio app (requires authentication)
  4. Logout (/logout): Clears session and redirects to homepage

Project Structure

.
├── app.py                    # Main FastAPI application
├── setup_oauth.py           # Interactive OAuth setup script
├── GOOGLE_OAUTH_SETUP.md    # Detailed OAuth setup guide
├── requirements.txt         # Python dependencies
├── env.example             # Environment variables template
├── setup.sh                # Setup script
├── run.sh                  # Run script
├── README.md               # This file
└── venv/                   # Virtual environment (created by setup)

Development

Manual Setup (Alternative)

If you prefer manual setup:

# Create virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
cp env.example .env
# Edit .env with your credentials

# Run the app
python -m uvicorn app:app --host 0.0.0.0 --port 8000 --reload

Environment Variables

Variable Description Required
GOOGLE_CLIENT_ID Google OAuth Client ID Yes
GOOGLE_CLIENT_SECRET Google OAuth Client Secret Yes
SECRET_KEY Session encryption key Yes
HOST Server host (default: 0.0.0.0) No
PORT Server port (default: 8000) No
DEBUG Debug mode (default: True) No

Security Notes

  • Never commit your .env file to version control
  • Use a strong, random SECRET_KEY
  • Keep your OAuth credentials secure
  • The app uses session-based authentication

Troubleshooting

Common Issues

  1. "Virtual environment not found"

    • Run ./setup.sh first
  2. "Dependencies not installed"

    • Activate virtual environment: source venv/bin/activate
    • Install dependencies: pip install -r requirements.txt
  3. OAuth errors

    • See GOOGLE_OAUTH_SETUP.md for detailed troubleshooting
    • Verify your Google OAuth credentials in .env
    • Check that redirect URI is set to http://localhost:8000/auth
  4. Port already in use

    • Change the PORT in .env file
    • Or kill the process using the port

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages