Files
microdot/examples/auth/token_auth.py
Miguel Grinberg 7bc66ce3bb auth examples
2024-04-28 00:32:06 +01:00

27 lines
436 B
Python

from microdot import Microdot
from microdot.auth import TokenAuth
app = Microdot()
auth = TokenAuth()
TOKENS = {
'susan-token': 'susan',
'david-token': 'david',
}
@auth.authenticate
async def check_token(request, token):
if token in TOKENS:
return TOKENS[token]
@app.route('/')
@auth
async def index(request):
return f'Hello, {request.g.current_user}!'
if __name__ == '__main__':
app.run(debug=True)