sanic-token-auth
sanic-token-auth copied to clipboard
headers
Hello,
how do I send the key and secret in a header ?
When I do:
import requests
import json
headers = {"X-My-App-Auth-Token": "utee3Quaaxohh1Oo"}
data = {'key':'value'}
data =json.dumps(data)
r = requests.post('http://0.0.0.0:8000/json/',data=data,headers=headers)
and on the server side:
from sanic import Sanic
from sanic import response
from sanic_token_auth import SanicTokenAuth
app = Sanic(__name__)
auth = SanicTokenAuth(app, secret_key='utee3Quaaxohh1Oo', header='X-My-App-Auth-Token')
@app.route("/json", methods=['GET', 'POST'])
@auth.auth_required
def post_json(request):
data = request.json
return response.json(data)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
This doesn't work. (Without header it works) Could you please let me know how to phrase the header ? Thanks
Any update on this?
Thanks for reporting the issue! I'll take a look on the weekend and get back.
@baeriswyld @ohld I've just checked and confirm that it in fact does not work with synchronous handlers. However, with async def post_json(request)
it works as expected. One of the main ideas behind Sanic is asyncio, so it's expected to have [most of] handlers using async.