Skip to main content

Injectable FastAPI auth via OIDC

Project description

Build Status Build Documentation

Python Versions PyPI Versions License

An Omnivector initiative

omnivector-logo

Armasec

Adding a security layer on top of your API can be difficult, especially when working with an OIDC platform. It's hard enough to get your OIDC provider configured correctly. Armasec aims to take the pain out of securing your APIs routes.

Armasec is an opinionated library that attempts to use the most obvious and commonly used workflows when working with OIDC and making configuration as simple as possible.

When using the Armasec helper class, you only need two configuration settings to get going:

  1. Domain: the domain of your OIDC provider
  2. Audience: An optional setting that restricts tokens to those intended for your API.

That's it! Once you have those settings dialed in, you can just worry about checking the permissions scopes of your endpoints

Documentation

Documentation is hosted hosted on github.io at the Armasec homepage.

Quickstart

  1. Install armasec and uvicorn:
pip install armasec uvicorn
  1. Save th Minimal Example (example.py) locally:
import os

from armasec import Armasec
from fastapi import FastAPI, Depends


app = FastAPI()
armasec = Armasec(
    domain=os.environ.get("ARMASEC_DOMAIN"),
    audience=os.environ.get("ARMASEC_AUDIENCE"),
)

@app.get("/stuff", dependencies=[Depends(armasec.lockdown("read:stuff"))])
async def check_access():
    return dict(message="Successfully authenticated!")
  1. Set the Armasec environment variables:
  • ARMASEC_DOMAIN
  • ARMASEC_AUDIENCE
  1. Run the app
uvicorn --host 0.0.0.0 example:app

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

armasec-3.0.2.tar.gz (3.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

armasec-3.0.2-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file armasec-3.0.2.tar.gz.

File metadata

  • Download URL: armasec-3.0.2.tar.gz
  • Upload date:
  • Size: 3.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for armasec-3.0.2.tar.gz
Algorithm Hash digest
SHA256 8db828bc5626de02b33eea259489ae35f309be345e4919b382a654c3ef5e61d1
MD5 e4e7132fed93a3c455c082369eeee55b
BLAKE2b-256 3a2fc9063d10b5ce5b643d26e8d191db2bf056606c7116c7f2aa00a5ce8cf93c

See more details on using hashes here.

File details

Details for the file armasec-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: armasec-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for armasec-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da4cf534a1119c1e4a419757374e164cfb78ffc44205a14f3b90039823d32f5a
MD5 d63692f7c7865770c718f89a2a01fd3b
BLAKE2b-256 ede656eb7e2876d0f64f46e2f00468f8489ccf465ef3cb4955418fb930bf8ef2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page