Authentication backends and helpers for Starlette-based apps and frameworks
Project description
starlette-auth-toolkit
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. You can choose to perform a database query, use environment variables or private files, etc.
Base backends are user model agnostic, although we recommend you use a subclass of starlette.authentication.BaseUser
.
The documentation below lists which scopes each backend grants when authentication succeeds.
Please refer to the Starlette authentication documentation for more information on Starlette's authentication and permissions interface.
Basic auth
Abstract methods
-
.verify(self, username: str, password: str) -> Optional[BaseUser]
If
username
andpassword
are valid, return the corresponding user. Otherwise, returnNone
.
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
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
Built Distribution
File details
Details for the file starlette-auth-toolkit-0.1.0.tar.gz
.
File metadata
- Download URL: starlette-auth-toolkit-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90867e9250b65be9e98002c0b9238d3acaf917e7b515338685ae38425c57832e |
|
MD5 | 2543ea7bfd2435069c90f2929469e776 |
|
BLAKE2b-256 | 21b7ac79a9728e76eff8744f2ea0237e3b1c96cc40a91796916785d6994e2259 |
File details
Details for the file starlette_auth_toolkit-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: starlette_auth_toolkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d229a6ecf4d3c2275908861955a2bc75472bbd394a1687fc729a34f2fae2e530 |
|
MD5 | a1592623a88133ff1d8b6c5b7334a9f0 |
|
BLAKE2b-256 | 43603945f9d2ce54e41f71cb6cf098732dc12a5c34900e605ec9c5cbb5966a4f |