Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + Permit.io Integration

This repository demonstrates how to integrate Permit.io with FastAPI to implement robust, multi-tenant Role-Based Access Control (RBAC).

Features

  • FastAPI integration with Permit.io SDK
  • User synchronization with Permit.io
  • Multi-tenant RBAC enforcement via middleware
  • Protected API endpoints with permission checks

Prerequisites

  • Python 3.8 or higher
  • A Permit.io account and API key
  • Basic understanding of FastAPI and RBAC concepts

Installation

  1. Clone this repository:
git clone https://github.com/Tabintel/permit-fastapi.git
cd permit-fastapi
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file with your Permit.io API key:
PERMIT_API_KEY=your_permit_api_key
PERMIT_PDP_URL=http://localhost:7766

Running the Application

Start the FastAPI server:

uvicorn main:app --reload

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

API Endpoints

  • GET / - Welcome message
  • GET /admin - Admin dashboard (requires 'view' permission on 'admin_dashboard')
  • GET /profile - User profile (requires 'view' permission on 'user_profile')
  • POST /sync-user - Sync a user with Permit.io

Project Structure

  • main.py - FastAPI application and routes
  • permit_client.py - Permit.io SDK initialization
  • middleware/authorize.py - Authorization middleware
  • utils/sync_user.py - User synchronization utility

Learn More

For more information about Permit.io and FastAPI:

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages