Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yusufusta/sanicapikey

Simple api key based auth plugin for Sanic
https://github.com/yusufusta/sanicapikey

Last synced: about 2 months ago
JSON representation

Simple api key based auth plugin for Sanic

Awesome Lists containing this project

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 SanicApiKey

app = 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)
```