| 1 | from ninja import NinjaAPI, Form |
| 2 | from ninja.security import HttpBearer |
| 3 | |
| 4 | |
| 5 | class GlobalAuth(HttpBearer): |
| 6 | def authenticate(self, request, token): |
| 7 | if token == "supersecret": |
| 8 | return token |
| 9 | |
| 10 | |
| 11 | api = NinjaAPI(auth=GlobalAuth()) |
| 12 | |
| 13 | # @api.get(...) |
| 14 | # def ... |
| 15 | # @api.post(...) |
| 16 | # def ... |
| 17 | |
| 18 | |
| 19 | @api.post("/token", auth=None) # < overriding global auth |
| 20 | def get_token(request, username: str = Form(...), password: str = Form(...)): |
| 21 | if username == "admin" and password == "giraffethinnknslong": |
| 22 | return {"token": "supersecret"} |