How can I get my bottle.py app (Running in Paste or Cherrypy) to do HTTP (basic or digest) authentication? - I need to secure it, but cant find a any HOWTOs.
Bottle.py HTTP Auth?
Asked Answered
possible duplicate of How to implement user authentication and sessions with Python –
Wrangler
possible duplicate of Bottle-friendly WSGI authentication library/middleware –
Stokeontrent
bottle has a built in auth_basic
decorator that can be used on a view:
from bottle import auth_basic, request, route
def check(user, pw):
# Check user/pw here and return True/False
@route('/')
@auth_basic(check)
def home():
return { 'data': request.auth }
Can you explain more? I am not sure how I can do check. –
Wallenstein
That's not a lot of information to go on, I'm afraid. Your
check
function depends entirely on what you want to do, so it could say e.g. if user == "user" and pw == "hello": return True
– though in general of course I would not hard code a password like that! –
Lowestoft What happens if you fail the check? Can you decide what is shown? –
Ailbert
The auth_basic parameters are the function to call, the name of the auth realm, and the body to be displayed in the 401 error, so you can pass it in there. –
Lowestoft
There are some libraries on GitHub like https://github.com/FedericoCeratto/bottle-cork that should help. It may be easier to integrate than the repoze library suggested in the related post.
© 2022 - 2024 — McMap. All rights reserved.