Created
September 19, 2014 18:59
-
-
Save doobeh/cee7189dea5d744adac9 to your computer and use it in GitHub Desktop.
Application showing how to use Flask-HTTPAuth easily from multiple files.
This file contains hidden or 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
from flask import Flask | |
from authy import auth | |
def create_app(): | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = 'hmm.' | |
from views import mod as exampleMod | |
app.register_blueprint(exampleMod) | |
return app | |
app = create_app() | |
@app.route('/') | |
@auth.login_required | |
def index(): | |
return "Hello, %s!" % auth.username() | |
if __name__ == '__main__': | |
app.run(debug=True) |
This file contains hidden or 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
from flask.ext.httpauth import HTTPDigestAuth | |
auth = HTTPDigestAuth() | |
users = { | |
"john": "hello", | |
"susan": "bye" | |
} | |
@auth.get_password | |
def get_pw(username): | |
if username in users: | |
return users.get(username) | |
return None |
This file contains hidden or 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
from flask import Blueprint | |
from authy import auth | |
mod = Blueprint('example', __name__) | |
@mod.route('/hmm/') | |
@auth.login_required | |
def hmm(): | |
return 'Hmmmm' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment