Qijiang60 / fastapimsal

Authorization for FastAPI using Microsoft Azure Active Directory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FastAPI Auth

This is a WIP and should not be used in production

Authenticate users with FastAPI using the Microsoft MSAL Library and Azure Active Directory.

Getting started

Python dependencies

To get started install Poetry.

Then ensure all dependencies are installed:

poetry install

Pre-commit

Run to make CI-tests pass

poetry run pre-commit run --all-files

Examples

See examples/app.py for a simple example.

Create a .auth.env file:

echo "session_expire_time_minutes=1
session_secret=<Session-Cookie-Secret>
client_id=<Application-client-id>
client_secret=<Application-Client-secret>
tenant_id=<Tenant-id" > .auth.env

For the session_secret its a good idea to create a secret with openssl rand -hex 32

To run the example

poetry run uvicorn --reload --app-dir examples app:app --reload-dir examples

About

Authorization for FastAPI using Microsoft Azure Active Directory

License:MIT License


Languages

Language:Python 100.0%