Skip to content

Instantly share code, notes, and snippets.

@doobeh
Created September 19, 2014 18:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doobeh/cee7189dea5d744adac9 to your computer and use it in GitHub Desktop.
Save doobeh/cee7189dea5d744adac9 to your computer and use it in GitHub Desktop.
Application showing how to use Flask-HTTPAuth easily from multiple files.
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)
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
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