Search code examples
pythonbottle

Basic auth in Bottle & Sending a file to user's browser


i'm trying to perform basic authentication in bottle framework

def is_authenticated_user(user, password): 
    # This function is called to check if a username/password combination is valid
    return username == 'nikos' and password == ******'

and call it as:

@app.route( '/file', methods=['POST'] )
@auth_basic( is_authenticated_user ) 
.... 
.... 
filename = request.form.get('filename') return static_file( filename, root='/home/nikos/wsgi/static/files' )

I'm having trouble making this work, i dont understnad why i'm getting the error method not allowed. Also is the static_file function the correct way to send a file to the user's browser?


Solution

  • i cannot retrieve the username given to the prompt as request.auth.username nor as request.auth.user. How can i grab that value?

    According to the documentation, request.auth is a tuple of (user, password). Retrieve the username like this:

    username = request.auth[0]