Skip to content

A lightweight FastAPI skeleton for building secure, scalable REST APIs. Includes JWT-based authentication, Google Drive integration using OAuth2, and modular, clean architecture for rapid development.

Notifications You must be signed in to change notification settings

DarinelGuillen/FastAPI-Secure-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Project Documentation

Overview

This API is built with FastAPI to manage authentication and perform operations with Google Drive. It includes login functionality, file listing from Google Drive, and uses JWT tokens for secure authentication.


Requirements

  • Python 3.11
  • FastAPI
  • Uvicorn
  • Python-dotenv
  • Google-auth libraries

Installation

  1. Clone the Repository:

    git clone https://github.com/your-repo-name.git
    cd api_project
  2. Create a Virtual Environment:

    python3.11 -m venv venv
    .\venv\Scripts\Activate
  3. Install Dependencies:

    pip install -r requirements.txt

    Or manually:

    pip install fastapi uvicorn python-dotenv google-auth google-auth-oauthlib google-api-python-client
  4. Set Up Environment Variables: Create a .env file in the root directory with the following:

    GOOGLE_CLIENT_ID=your-google-client-id
    GOOGLE_CLIENT_SECRET=your-google-client-secret
    SECRET_KEY=your-secret-key
    ALGORITHM=HS256
    ACCESS_TOKEN_EXPIRE_MINUTES=30
    

Run the Application

Start the server using Uvicorn:

.\venv\Scripts\Activate
uvicorn app.main:app --reload

The API will be accessible at http://localhost:8000.


Features

Authentication

  • Login Endpoint: /auth/login
    • Accepts username and password using OAuth2PasswordRequestForm.
    • Returns a JWT token.

Google Drive Integration

  • Authorize: /drive/authorize
    • Redirects the user to the Google authentication page.
  • Callback: /drive/oauth2callback
    • Handles the OAuth2 callback.
  • List Files: /drive/files
    • Lists the user’s Google Drive files.

Example Endpoint

  • /hello: Returns a simple JSON response: {"message": "Hello World"}.

Project Structure

api_project/
├── app/
│   ├── main.py                 # Entry point for the API
│   ├── core/
│   │   ├── config.py           # Configuration and environment variables
│   │   ├── security.py         # Security-related utilities
│   ├── models/
│   │   ├── user.py             # User models
│   ├── routers/
│   │   ├── auth.py             # Authentication routes
│   │   ├── drive.py            # Google Drive routes
│   ├── schemas/
│   │   ├── user.py             # Data validation for users
│   │   ├── drive.py            # Data validation for Drive operations
│   ├── services/
│   │   ├── auth.py             # Token generation and verification
│   │   ├── google_drive.py     # Google Drive API interactions
│   ├── utils/
│   │   ├── helpers.py          # Helper utilities

Testing

About

A lightweight FastAPI skeleton for building secure, scalable REST APIs. Includes JWT-based authentication, Google Drive integration using OAuth2, and modular, clean architecture for rapid development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages