Skip to main content

paella

Simple Asynchronous Auth library

*WARNING*

THIS REPOSITORY CONTAINS SECRETS FOR USE IN TESTING

DO NOT REUSE THESE SECRETS FOR PRODUCTION

requirements

  • python >= 3.11 (uses modern union typehints)

dependencies

  • pyjwt[crypto] >= 2.8.0"

testing

I deliberately included a test keypair, please see the warning above.

test data

In ./tests/db/test_users.db there is minimal prepopulated data:

sqlite> .schema Users
CREATE TABLE Users (id int primary key not null, email char(128) not null, password char(128) not null);
sqlite> select * from Users;
1|testuser@test.com|a_very_basic_password
2|testuser2@test.com|65332c4349d159ab3d41b8e1a01db7d77928f1b8215fd345e19e5cfe016f468a

testuser2@test.com has a sha256 hash of the following string: salt+basic_password

Usage

Creating auth object

By default uses RSA public/private keys. PyJWT does not have a concept of unencrypted JWTs. This project is designed specifically to rely on asynchronous RSA keypairs, which means that you do not have to use it for authentication, but can use it for authorization so long as the pubkey and the authorization function are properly configured.

Initially you can create an empty auth object (if you so desire) that doesn't really do anything:

from paella import Paella

auth: Paella = Paella()

Authentication (authn) Function

The authentication function takes in an id and a secret and returns a boolean or a dict. If a dict is returned, that is then used to populate a JWT with custom claims or override the defaults, otherwise the defaults are used if the value returned is True.

The authentication function itself must have a function signature that matches the below:

async def authn(connection: Any, id: str, secret: str) -> dict | bool:

Authorization (authz) Function

The authorization function takes in a dict and returns a boolean.

The authorization function itself must have a function signature that matches the below:

async def authz(connection: Any, *args, **kwargs) -> bool:

Caveats

uses a passed function to evaluate authentication and authorization, this function can be asynchronous (and probably should be)

This assumes two things - first, that you are setting up a connection object of some sort (if necessary) and secondly that your authentication and authorization functions accurately perform their duties.

For example: it is 100% acceptable to have a authorization function that lools like this:

async def authenticate(cxobj: Any, id: str, secret: str) -> bool:
    return True

or

async def authenticate(cxobj: Any, id: str, secret: str) -> bool:
    return False

The first will always pass, the second will always fail, being their return values are True and False respectively.

Metadata

Release files for paella-auth 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for paella-auth 0.5.0
File Size Uploaded
paella_auth-0.5.0.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for paella-auth 0.5.0
File Interpreter ABI Platform
paella_auth-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / paella_auth-0.5.0.tar.gz

Download URL paella_auth-0.5.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b169c081e222559ede82636efae32578fbb5194214541447e0921cae0063b771
BLAKE2b-256 checksum
How to use checksums
ee5033ea1f99cef20599ccf7d9e35af6ce164c33c999887e2c7e5bceb1eb17fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / paella_auth-0.5.0-py3-none-any.whl

Download URL paella_auth-0.5.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1b82e09df3985d591ef3f523194a87ddb71874ee9ad6f6f45643608394f1294
BLAKE2b-256 checksum
How to use checksums
0c3a0a79e09b1294022147f3dab03d638707d94895158395f3140fa693340d05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page