0

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?

  • What are your request headers? – Daniel Sep 23 '18 at 08:30
  • How can i check what they are to show you?! – Νικόλαος Βέργος Sep 23 '18 at 12:03
  • Do `print(request.headers)` in `is_authenticated_user` and show the output. – Daniel Sep 23 '18 at 15:14
  • Actually i was able to make the basic_auth to work.
    If you want please help me with this issue which si driving me crazy https://stackoverflow.com/questions/52466285/method-is-not-allowed-when-i-add-post-as-a-method-in-a-view-function
    – Νικόλαος Βέργος Sep 23 '18 at 15:44
  • Oh and also i cannot retrieve the username given to the prompt as `request.auth.username` nor as `request.auth.user`. How can i grab that value? – Νικόλαος Βέργος Sep 23 '18 at 16:21
  • Just left you an answer to your latest question here, hope it helps. Side note: please ask exactly 1 question per question. Here you have asked 3. If you ask more than 1, people will vote to close your questions, because it makes clearly answering them difficult. (Note that I did not vote to close this or downvote it, but others will if you don't stick to this site's conventions.) – ron rothman Sep 24 '18 at 13:22

1 Answers1

1

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]
ron rothman
  • 17,348
  • 7
  • 41
  • 43