Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Quiec/sanicapikey
Simple api key based auth plugin for Sanic
https://github.com/Quiec/sanicapikey
Last synced: 4 months ago
JSON representation
Simple api key based auth plugin for Sanic
- Host: GitHub
- URL: https://github.com/Quiec/sanicapikey
- Owner: yusufusta
- Created: 2020-11-01T15:03:08.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-01T15:15:09.000Z (about 4 years ago)
- Last Synced: 2024-08-18T12:05:15.859Z (4 months ago)
- Language: Python
- Size: 1.95 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-sanic - SanicApiKey
README
# Sanic Api Key
Basic support for API Keys. Support form, args, header.## Installion
```sh
pip install sanicapikey
```## Example Usage
```python
from sanic import Sanic
from sanic.response import text, json
from SanicApiKey import SanicApiKeyapp = Sanic('test')
async def test(request):
return json({ "error": 'invalid api key' })auth = SanicApiKey(app, 'api_key', keys=['hello', 'world'], error=test)
# Header:
# auth = SanicApiKey(app, header='api_key', keys=['hello', 'world'], error=test)# Form
# auth = SanicApiKey(app, form='api_key', keys=['hello', 'world'], error=test)@app.route('/')
@auth.key_required
async def test(request):
return json({'success': True, 'key': auth.get_token()})if __name__ == '__main__':
app.run(host='localhost', port=8000)
```