Skip to content
Authentication backends and helpers for Starlette-based apps and frameworks
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts
starlette_auth_toolkit
tests
.bumpversion.cfg
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
MANIFEST.in
README.md
requirements.txt
setup.py

README.md

starlette-auth-toolkit

travis black python pypi license

Authentication backends and helpers for Starlette-based apps and frameworks.

Note: documentation is in progress — in the meantime, feel free to read the source code!

Installation

pip install starlette-auth-toolkit

Note: you need to install Starlette yourself.

Base backends

Base backends implement an authentication flow, but the exact implementation of credentials verification is left up to you. This means you can choose to perform a database query, use environment variables or private files, etc.

These backends grant a set of scopes when authentication succeeds.

Base backends are user model agnostic, although we recommend you implement the interface specified by starlette.authentication.BaseUser (see also Starlette authentication).

Basic auth

Abstract methods

  • .verify(self, username: str, password: str) -> Optional[BaseUser]

    If username and password are valid, return the corresponding user. Otherwise, return None.

Scopes

  • authenticated

Example

# myapp/auth.py
from starlette.authentication import SimpleUser  # or a custom user model
from starlette_auth_toolkit.backends import BaseBasicAuthBackend

class BasicAuthBackend(BaseBasicAuthBackend):
    async def verify(self, username: str, password: str):
        # TODO: you'd probably want to make a DB call here.
        if (username, password) != ("guido", "s3kr3t"):
            return None
        return SimpleUser(username)

Contributing

Want to contribute? Awesome! Be sure to read our Contributing guidelines.

Changelog

See CHANGELOG.md.

License

MIT

You can’t perform that action at this time.