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(
    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-1.3.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

armasec-1.3.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: armasec-1.3.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.8.17 Linux/6.2.0-1018-azure

File hashes

Hashes for armasec-1.3.0.tar.gz
Algorithm Hash digest
SHA256 cf2362d62dea755fd9a262038a4ea9eaf39ffaeb2a6159402ad2aff393f0aa0c
MD5 3558f89036ab1ddd284a848c5930ef2c
BLAKE2b-256 7c53835f5d357864da6b78634e759eea5bcf517bfaa0a9369ecfba9e5d75378b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: armasec-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.8.17 Linux/6.2.0-1018-azure

File hashes

Hashes for armasec-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd9063a5c1da0610594615ec1288c776a7565e34061754e3f1aa4942a8974cd6
MD5 5b734b5bcf8b195b76e4dfb8c0a6bbfe
BLAKE2b-256 c5e64167a93846b87f608196b92ed866e9e96babb9d30bbb00329d3d0c6de00a

See more details on using hashes here.

Supported by

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