Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI with MSAL (Microsoft Authentication Library) Integration

This project demonstrates how to integrate FastAPI with Microsoft Authentication Library (MSAL) to enable Azure AD SSO authentication.

Project Structure

fastapi-msal/
├── app/
│   ├── api/
│   │   └── v1/
│   │       ├── __init__.py
│   │       └── api.py
│   ├── auth/
│   │   └── __init__.py
│   ├── core/
│   │   ├── __init__.py
│   │   └── config.py
│   ├── db/
│   │   └── __init__.py
│   ├── models/
│   │   └── __init__.py
│   ├── schemas/
│   │   └── __init__.py
│   ├── tests/
│   │   ├── __init__.py
│   │   ├── conftest.py
│   │   └── test_setup.py
│   ├── __init__.py
│   └── main.py
├── .env.example
├── .gitignore
├── requirements.txt
└── README.md

Setup Instructions

Prerequisites

  • Python 3.9 or higher
  • Azure AD tenant with admin access (for creating application registration)

Virtual Environment Setup

  1. Create a virtual environment:

    python -m venv venv
  2. Activate the virtual environment:

    • On Windows:
      venv\Scripts\activate
    • On macOS/Linux:
      source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt

Environment Configuration

  1. Copy the .env.example file to .env:

    cp .env.example .env
  2. Update the .env file with your Azure AD application details and other settings.

Running the Application

Start the development server:

uvicorn app.main:app --reload

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

API documentation is available at:

Running Tests

Run the tests using pytest:

pytest

Features

  • FastAPI application with API versioning
  • Azure AD SSO authentication via MSAL
  • CORS configuration
  • Configuration using Pydantic v2 Settings
  • Logging setup
  • Health check endpoints

About

Microsoft 365 SSO Integration with FastAPI + MSAL

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages