Starlette OAuth2
A Startlette middleware for authentication through oauth2.
This middleware is intented to be used when the application relies on an external tenant (e.g. Microsoft AD) for authentication.
It assumes that a user that is not authenticated is not authorized to do anything.
Check example/ for a concrete implementation.
How to run the example against Microsoft AD
Note: the values in capital such as CLIENT_ID are to be replaced in example/.venv.
-
Generate a secret and write its value on
SECRET_KEY -
Go to Azure AD, create an app registration (
app registrations), give it a name, and addhttp://localhost:5001/authorizedas aRedirect URI.- replace the value on
CLIENT_IDby the value onApplication (client) ID - replace the value on
TENANT_IDby the value onDirectory (tenant) ID
- replace the value on
-
In
Certificates & secrets, create a new client secret.- replace the value on
CLIENT_SECRETby the value of the key you just created underClient secrets
- replace the value on
-
Install dependencies and run:
cd examples
python -m venv venv
venv/bin/pip install -r requirements.txt
python -m app
When you visit http://localhost:5001/public, you will see that you are not authenticated.
When you visit http://localhost:5001, you will be redirected to your tenant, to authenticate. Once authenticated, you will
be redirected back to http://localhost:5001, and your email will appear.
Public endpoints are optional. They are useful e.g. for healthchecks.
Metadata
Release files for starlette-oauth2 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| starlette-oauth2-0.2.0.tar.gz | 3.6 kB | Without provenance | Details |
Release files / starlette-oauth2-0.2.0.tar.gz
| Download URL | starlette-oauth2-0.2.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e67e9f285ce078a8b96e3aca5aa2174a1b8b56607e6fd5f0130ef6dde02be1dd
|
|
BLAKE2b-256 checksum How to use checksums |
1af803449428516e11ee6614b1b7ee0dfd63829eaf50cfb9b23c4551e8174c0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.3
|
Security for starlette-oauth2 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.