add authentication

This commit is contained in:
Martin
2016-05-11 16:05:42 +02:00
parent f41a16f041
commit 9ced739ef6
3 changed files with 28 additions and 3 deletions
+17 -1
View File
@@ -1,4 +1,4 @@
from flask import Flask, jsonify
from flask import Flask, jsonify, Response, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
@@ -17,6 +17,22 @@ from api.views import designers
app.register_blueprint(designers.mod)
def check_authentication():
auth = request.authorization
if not auth:
return False
return auth.username in app.config.get("API_KEYS")
@app.before_request
def authenticate():
if not check_authentication():
return Response(
'No valid API key provided', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'}
)
@app.route("/")
def index():
data = {