add authentication
This commit is contained in:
+17
-1
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user