Bottle.py HTTP Auth?

James Bennet picture James Bennet · Nov 7, 2012 · Viewed 10.6k times · Source

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.

Answer

M Somerville picture M Somerville · May 11, 2014

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 }