Skip to main content

A very micro http framework.

Project description

yhttp-auth

PyPI Build Coverage Status

Authentication extension for yhttp.

Install

pip install yhttp-pony

Usage

from yhttp import Application
from yhttp.ext.auth import install as auth_install


app = Application()
auth = auth_install(app)
app.settings.merge(f'''
auth:
  redis:
    host: localhost
    port: 6379
    db: 0

  token:
    algorithm: HS256
    secret: foobar

  refresh:
    key: yhttp-refresh-token
    algorithm: HS256
    secret: quxquux
    secure: true
    httponly: true
    maxage: 2592000  # 1 Month
    domain: example.com
''')


@app.route('/reftokens')
@yhttp.statuscode(yhttp.statuses.created)
def create(req):
    app.auth.set_refreshtoken(req, 'alice', dict(baz='qux'))

@app.route('/tokens')
@yhttp.statuscode(yhttp.statuses.created)
@yhttp.text
def refresh(req):
    reftoken = app.auth.verify_refreshtoken(req)
    return app.auth.dump_from_refreshtoken(reftoken, dict(foo='bar'))

@app.route('/admin')
@auth(roles='admin, god')
@yhttp.text
def get(req):
    return req.identity.roles

app.ready()

Command line interface

setup.py

setup(
    ...
    entry_points={
        'console_scripts': [
            'myapp = myapp:app.climain'
        ]
    },
    ...
)
myapp auth --help

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for yhttp-auth, version 3.7.0
Filename, size File type Python version Upload date Hashes
Filename, size yhttp_auth-3.7.0-py3.8.egg (11.6 kB) File type Egg Python version 3.7.0 Upload date Hashes View
Filename, size yhttp-auth-3.7.0.tar.gz (6.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page