Created
September 13, 2012 12:02
-
-
Save joelverhagen/3713895 to your computer and use it in GitHub Desktop.
HTTP Basic Authorization with Flask and Flask-Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flask, http://flask.pocoo.org/ | |
# Flask-Login, https://github.com/maxcountryman/flask-login | |
@app.before_request | |
def basic_authorize(): | |
auth = request.authorization | |
if not current_user.is_active() and auth and auth.type == 'basic': | |
# change to your specific call to get the user based off username and password | |
# you're hopefully bcrypting your password, so fetch by username then check password :) | |
user = User.get_login_user(unicode(auth.username), unicode(auth.password)) | |
if user is not None: | |
login_user(user) | |
else: | |
return 'The provided username and password are invalid.', 403 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://flask-login.readthedocs.io/en/latest/#custom-login-using-request-loader