Skip to content
Snippets Groups Projects
app.py 1.38 KiB
Newer Older
Luka's avatar
Luka committed
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
Luka's avatar
Luka committed

# These imports are required
from areas import api_v1
from areas import web

from areas import users
from areas import apps
from areas import auth
from areas import login


from helpers import (
    BadRequest,
    KratosError,
Luka's avatar
Luka committed
    HydraError,
    bad_request_error,
    validation_error,
    kratos_error,
    global_error,
Luka's avatar
Luka committed
    hydra_error,
Luka's avatar
Luka committed
from config import *
Luka's avatar
Luka committed

app = Flask(__name__)
cors = CORS(app)
app.config["SECRET_KEY"] = SECRET_KEY

app.logger.setLevel(logging.INFO)                                            

Luka's avatar
Luka committed
app.register_blueprint(api_v1)
app.register_blueprint(web)
Luka's avatar
Luka committed

# 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)
Luka's avatar
Luka committed
app.register_error_handler(HydraError, hydra_error)
Luka's avatar
Luka committed
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
Luka's avatar
Luka committed


Luka's avatar
Luka committed
def index():
    return "Open App Stack API v1.0"