First try at Basic Auth.

This commit is contained in:
Zbigniew Siciarz
2011-06-13 15:33:39 +02:00
parent f5612eecfa
commit d42b798b26
2 changed files with 18 additions and 2 deletions
+10 -1
View File
@@ -18,7 +18,7 @@ from time import time as now
from decorator import decorator
from flask import Flask, Response, request, render_template, redirect, g
from .helpers import get_files, get_headers, status_code, get_dict
from .helpers import get_files, get_headers, status_code, get_dict, check_basic_authorization
app = Flask(__name__)
@@ -196,5 +196,14 @@ def set_cookie(name, value):
return response
@app.route('/basic-auth')
def basic_auth():
"""Prompts the user for authentication using HTTP Basic Auth."""
if not check_basic_authorization():
return status_code(401)
return app.make_response('auth ok')
if __name__ == '__main__':
app.run()
+8 -1
View File
@@ -108,4 +108,11 @@ def status_code(code):
if 'headers' in m:
r.headers = m['headers']
return r
return r
def check_basic_authorization():
"""Checks user authentication using HTTP Basic Auth."""
auth = request.authorization
return auth and auth.username == "httpbin" and auth.password == "secret"