dashboard/app.py

51 lines
1.2 KiB
Python
Raw Normal View History

2021-09-27 12:03:35 +02:00
from flask import Flask, jsonify
from flask_jwt_extended import JWTManager
from flask_cors import CORS
from jsonschema.exceptions import ValidationError
from werkzeug.exceptions import BadRequest
2021-09-27 12:03:35 +02:00
# These imports are required
2021-10-28 16:09:10 +02:00
from areas import api_v1
from areas import users
from areas import apps
from areas import auth
from helpers import (
BadRequest,
KratosError,
2022-01-18 10:48:18 +01:00
HydraError,
bad_request_error,
validation_error,
kratos_error,
global_error,
2022-01-18 10:48:18 +01:00
hydra_error,
)
2021-09-27 12:03:35 +02:00
from config import *
app = Flask(__name__)
cors = CORS(app)
app.config["SECRET_KEY"] = SECRET_KEY
2021-09-27 12:03:35 +02:00
app.register_blueprint(api_v1)
# Error handlers
app.register_error_handler(Exception, global_error)
app.register_error_handler(BadRequest, bad_request_error)
app.register_error_handler(ValidationError, validation_error)
app.register_error_handler(KratosError, kratos_error)
2022-01-18 10:48:18 +01:00
app.register_error_handler(HydraError, hydra_error)
2021-09-27 12:03:35 +02:00
jwt = JWTManager(app)
# When token is not valid or missing handler
@jwt.invalid_token_loader
@jwt.unauthorized_loader
@jwt.expired_token_loader
def expired_token_callback(*args):
return jsonify({"errorMessage": "Unauthorized"}), 401
2021-09-27 12:03:35 +02:00
@app.route("/")
2021-09-27 12:03:35 +02:00
def index():
return "Open App Stack API v1.0"