Skip to main content

Classic http auth

This package provides utils for authentication and authorization processes. Part of project "Classic".

Authentication usage

from classic.http_auth import authenticate


@join_point
@authenticate
def on_get_show_product(self, request, response):
    client = request.context.client

Client appears in request.context.client

For this you need to create instance in your core level code

from classic.http_auth import Authenticator

authenticator = Authenticator()

Decorate any controller as authentication needed (parameter "authenticator" will automatically describe in the constructor)

from classic.http_auth import authenticator_needed


@component
@authenticator_needed
class Catalog:
    catalog: services.Catalog
    ...

Decorators order is doesn't matter

Choose a properly strategy in your api factory code (adapter level) and put the authenticator in the controller

from classic.http_auth import strategies as auth_strategies

from simple_shop.adapters.shop_api import authenticator

authenticator.set_strategies(
    auth_strategies.JWT(
        secret_key='123',
    )
)

controller = controllers.Catalog(
    authenticator=authenticator,
    catalog=catalog,
)

You can pass multiple strategies to the authenticator. First succeed strategy will be winner
If all strategies failed exception will be raised

Authorization usage

This stage is doing after authentication

Define groups and permissions (access schema) in your core level code and pass this one to the authenticator

from classic.http_auth import Authenticator, Group, Permission

full_control = Permission('full_control')
read_only = Permission('read_only')

groups = (
    Group('admins', permissions=[full_control]),
    Group('managers', permissions=[read_only]),
    Group('guests'),
)

authenticator = Authenticator(app_groups=groups)

Apply authorization decorator to the controller method with needed groups and permission combination

from classic.http_auth import Group, authenticate


@authenticate
@authorize(Group('admin'))
def on_get_show_product(self, request, response):
   ...

You can combine groups and permissions as you want

from classic.http_auth import Group, Permission, authenticate, authorize


@authenticate
@authorize((Group('admin') & Group('foo')) | Permission('write'))
def on_get_show_product(self, request, response):
   ...

If access denied exception will be raised

Dependencies

falcon for pushing client info through HTTP
pyjwt for strategies

Tests and development mode

You can use dummy strategy

auth_strategy = auth_strategies.JWT(secret_key='123')
auth_dummy_strategy = auth_strategies.Dummy(
    login=login,
    name=name,
    groups=groups,
    email=email
)

if not is_dev:
    authenticator.set_strategies(auth_strategy)
else:
    authenticator.set_strategies(auth_dummy_strategy)

Dummy auth data appear in a client

Metadata

Release files for classic-http-auth 0.2.1

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

Source distribution (sdist)

Source distribution for classic-http-auth 0.2.1
File Size Uploaded Provenance
classic-http-auth-0.2.1.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for classic-http-auth 0.2.1
File Interpreter ABI Platform
classic_http_auth-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / classic-http-auth-0.2.1.tar.gz

Download URL classic-http-auth-0.2.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b5888be6b2156c6fb7714f3b358c854eeeb9a4ca0ceacc94595eb9a0449caeab
BLAKE2b-256 checksum
How to use checksums
19d3692f268c5df6b37aaacda4253edd674710feb58f4b229b3746182dacb0c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3

Release files / classic_http_auth-0.2.1-py3-none-any.whl

Download URL classic_http_auth-0.2.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
625907fc46872d5f81e2d145abb21abd25c3bf2ea2c84fef905a7e958e1dd614
BLAKE2b-256 checksum
How to use checksums
db754d50d0ea89ed05302ceb74f8463e257adc7b436e78444399d6d4cdd89252
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3

Security for classic-http-auth 0.2.1

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.

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