# yhttp-auth
[](https://pypi.python.org/pypi/yhttp-auth)
[](https://github.com/yhttp/yhttp-auth/actions/workflows/build.yml)
[](https://coveralls.io/github/yhttp/yhttp-auth?branch=master)
Authentication extension for [yhttp](https://github.com/yhttp/yhttp).
### Install
```bash
pip install yhttp-pony
```
### Usage
```python
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
```python
setup(
...
entry_points={
'console_scripts': [
'myapp = myapp:app.climain'
]
},
...
)
```
```bash
myapp auth --help
```
Raw data
{
"_id": null,
"home_page": "http://github.com/yhttp/yhttp-auth",
"name": "yhttp-auth",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Vahid Mardani",
"author_email": "vahid.mardani@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b6/19/8fdeeebc67e2ed8747338145877f8743b7e156995063ad1d31aba4c1cd9f/yhttp_auth-6.0.0.tar.gz",
"platform": null,
"description": "# yhttp-auth\n\n[](https://pypi.python.org/pypi/yhttp-auth)\n[](https://github.com/yhttp/yhttp-auth/actions/workflows/build.yml)\n[](https://coveralls.io/github/yhttp/yhttp-auth?branch=master)\n\n\nAuthentication extension for [yhttp](https://github.com/yhttp/yhttp).\n\n\n### Install\n\n```bash\npip install yhttp-pony\n```\n\n\n### Usage\n\n```python\nfrom yhttp import Application\nfrom yhttp.ext.auth import install as auth_install\n\n\napp = Application()\nauth = auth_install(app)\napp.settings.merge(f'''\nauth:\n redis:\n host: localhost\n port: 6379\n db: 0\n\n token:\n algorithm: HS256\n secret: foobar\n\n refresh:\n key: yhttp-refresh-token\n algorithm: HS256\n secret: quxquux\n secure: true\n httponly: true\n maxage: 2592000 # 1 Month\n domain: example.com\n''')\n\n\n@app.route('/reftokens')\n@yhttp.statuscode(yhttp.statuses.created)\ndef create(req):\n app.auth.set_refreshtoken(req, 'alice', dict(baz='qux'))\n\n@app.route('/tokens')\n@yhttp.statuscode(yhttp.statuses.created)\n@yhttp.text\ndef refresh(req):\n reftoken = app.auth.verify_refreshtoken(req)\n return app.auth.dump_from_refreshtoken(reftoken, dict(foo='bar'))\n\n@app.route('/admin')\n@auth(roles='admin, god')\n@yhttp.text\ndef get(req):\n return req.identity.roles\n\napp.ready()\n```\n\n### Command line interface\n\nsetup.py\n\n```python\n\nsetup(\n ...\n entry_points={\n 'console_scripts': [\n 'myapp = myapp:app.climain'\n ]\n },\n ...\n)\n\n```\n\n```bash\nmyapp auth --help\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A very micro http framework.",
"version": "6.0.0",
"project_urls": {
"Homepage": "http://github.com/yhttp/yhttp-auth"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "489ea567e4e9a536f1149fd2a588a4808bd653cbb1364b1902c2bfdaadc4d1a5",
"md5": "689d31639b01ecdc9102035c1c21b3d3",
"sha256": "f00a84be5e333c7cdeefc57e38f87c3f1e411f91c61a65e85d23fe4b866a0f41"
},
"downloads": -1,
"filename": "yhttp_auth-6.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "689d31639b01ecdc9102035c1c21b3d3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6407,
"upload_time": "2024-09-01T01:27:33",
"upload_time_iso_8601": "2024-09-01T01:27:33.870174Z",
"url": "https://files.pythonhosted.org/packages/48/9e/a567e4e9a536f1149fd2a588a4808bd653cbb1364b1902c2bfdaadc4d1a5/yhttp_auth-6.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b6198fdeeebc67e2ed8747338145877f8743b7e156995063ad1d31aba4c1cd9f",
"md5": "304a45ec95bee5fd836eab695ac5d142",
"sha256": "9194d01b932cffeff81d96f4ac0fdc7944a992c8eecfe1b19624a3ffeea575bd"
},
"downloads": -1,
"filename": "yhttp_auth-6.0.0.tar.gz",
"has_sig": false,
"md5_digest": "304a45ec95bee5fd836eab695ac5d142",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8534,
"upload_time": "2024-09-01T01:27:34",
"upload_time_iso_8601": "2024-09-01T01:27:34.943144Z",
"url": "https://files.pythonhosted.org/packages/b6/19/8fdeeebc67e2ed8747338145877f8743b7e156995063ad1d31aba4c1cd9f/yhttp_auth-6.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-01 01:27:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yhttp",
"github_project": "yhttp-auth",
"travis_ci": true,
"coveralls": true,
"github_actions": true,
"lcname": "yhttp-auth"
}