def create_app(config_object='museum_app.settings'):
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(config_object)
    mongo.init_app(app)
    # flask-graphql-auth bind
    auth = GraphQLAuth(app)
    # flask-jwt-extended bind
    jwt = JWTManager(app)

    # Endpoints
    app.add_url_rule('/web/',
                     view_func=FileUploadGraphQLView.as_view('web',
                                                             schema=web_schema,
                                                             graphiql=False))
    app.add_url_rule('/app/',
                     view_func=FileUploadGraphQLView.as_view('app',
                                                             schema=app_schema,
                                                             graphiql=False))
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # bind for alternative file up&download. routes found in museum_app.file
    app.register_blueprint(fileBP)
    return app
def create_app(test_config=None) -> App:
    app = App("fga")

    # load config
    configure(app=app, test_config=test_config)

    # extensions
    configure_database(app)

    # CLI
    manager = Manager(app)

    init_cli(app, manager)

    app.add_url_rule(
        "/graphql",
        view_func=GraphQLView.as_view("graphql",
                                      schema=schema,
                                      graphiql=True,
                                      context={"session": db.session}),
    )
    app.url_map.strict_slashes = False

    GraphQLAuth(app)

    app.migrate = Migrate(app, db)

    return app
Exemple #3
0
def create_app(*config_cls):
    app = Flask(__name__)

    for config in config_cls:
        app.config.from_object(config)

    print("[INFO] Flask application initialized with {0}".format([config.__name__ for config in config_cls]))

    Mongo(app)
    Schema(app)
    GraphQLAuth(app)

    return app
def flask_app():
    app = Flask(__name__)
    auth = GraphQLAuth(app)

    app.config["JWT_SECRET_KEY"] = "something"  # change this!
    app.config["REFRESH_EXP_LENGTH"] = 30
    app.config["ACCESS_EXP_LENGTH"] = 10

    schema = graphene.Schema(query=Query, mutation=Mutation)

    app.add_url_rule(
        "/graphql",
        view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True),
    )

    return app
Exemple #5
0
def create_app():
    global db, ma

    app = Flask(__name__)
    app.config.from_object('config')

    db.init_app(app)
    ma.init_app(app)

    Migrate(app, db)

    GraphQLAuth(app)

    init_graphql(app)
    init_cli(app)
    return app
Exemple #6
0
def create_app(config_name):
    app = Flask(__name__)
    CORS(app)
    FlaskJSON(app)
    GraphQLAuth(app)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    app.add_url_rule('/hairq',
                     view_func=GraphQLView.as_view('hairq',
                                                   schema=schema,
                                                   graphiql=True))

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        db_session.remove()

    return app
Exemple #7
0
def create_app(test_config=None):
    app = Flask(__name__)
    app.add_url_rule('/graphql',
                     view_func=GraphQLView.as_view('graphql',
                                                   schema=schema,
                                                   graphiql=True))

    GraphQLAuth(app)
    CORS(app)
    app.config['JWT_ACCESS_TOKEN_EXPIRES'] = 60
    app.config['JWT_SECRET_KEY'] = 'aVerySecretJwtSigningKey'

    @app.errorhandler(404)
    def page_not_found(e):
        return jsonify(
            {'message': 'The requested URL was not found on the server.'}), 404

    return app
Exemple #8
0
def create_app(*config_cls):
    app_ = Flask(__name__)

    for config in config_cls:
        app_.config.from_object(config)

    print('[INFO] Flask application initialized with {}'.format(
        [config.__name__ for config in config_cls]))

    GraphQLAuth().init_app(app_)
    Schema().init_app(app_)
    Mongo(app_)

    # @app_.after_request
    # def logger_ar(response):
    #     print("\n\n\n\n==========REQUEST LOG===============")
    #     print(request.data)
    #     print(request.headers)
    #     print("==========RESPONSE LOG===============")
    #     print(response.json)
    #     return response

    return app_
Exemple #9
0
import graphene
from flask_graphql_auth import (
    AuthInfoField,
    GraphQLAuth,
    get_jwt_identity,
    get_raw_jwt,
    create_access_token,
    create_refresh_token,
    query_jwt_required,
    mutation_jwt_required,
    mutation_jwt_refresh_token_required,
)
from flask_graphql import GraphQLView

app = Flask(__name__)
auth = GraphQLAuth(app)

app.config["JWT_SECRET_KEY"] = "something"  # change this!
app.config["REFRESH_EXP_LENGTH"] = 30
app.config["ACCESS_EXP_LENGTH"] = 10

user_claims = {"message": "VERI TAS LUX MEA"}


class MessageField(graphene.ObjectType):
    message = graphene.String()


class ProtectedUnion(graphene.Union):
    class Meta:
        types = (MessageField, AuthInfoField)
Exemple #10
0
from flask_graphql_auth import GraphQLAuth

###############################################################################
#
# Setup Flask-GraphQL-Auth
#
###############################################################################

# Getting pattoo configuration and setting JWT secrete key
config = Config()
PATTOO_API_WEB.config['JWT_SECRET_KEY'] = config.jwt_secret_key()
PATTOO_API_WEB.config['JWT_ACCESS_TOKEN_EXPIRES'] = config.acesss_token_exp()
PATTOO_API_WEB.config['JWT_REFRESH_TOKEN_EXPIRES'] = config.refresh_token_exp()

# Initialize authentication for pattoo api web flask app instance
auth = GraphQLAuth(PATTOO_API_WEB)

# Setup memcache. Required for all API imports
CACHE = Cache(PATTOO_API_WEB, config={'CACHE_TYPE': 'simple'})

# Import PATTOO_API_WEB Blueprints (MUST be done after CACHE)
from pattoo.api.web.graphql import GRAPHQL
from pattoo.api.web.rest import REST_API_DATA
from pattoo.api.web.status import API_STATUS

# Register Blueprints
PATTOO_API_WEB.register_blueprint(GRAPHQL, url_prefix=PATTOO_API_WEB_PREFIX)
PATTOO_API_WEB.register_blueprint(API_STATUS, url_prefix=PATTOO_API_WEB_PREFIX)
PATTOO_API_WEB.register_blueprint(REST_API_DATA,
                                  url_prefix=PATTOO_API_WEB_REST_PREFIX)
Exemple #11
0
# -*- coding: utf-8 -*-
"""
Extensions module.

Each extension is initialized in the app factory located in app.py.
"""
from flask_bcrypt import Bcrypt
from flask_caching import Cache
from flask_debugtoolbar import DebugToolbarExtension
from flask_graphql_auth import GraphQLAuth
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_wtf.csrf import CSRFProtect

bcrypt = Bcrypt()
csrf = CSRFProtect()
LOGIN = LoginManager()
db = SQLAlchemy()
MIGRATE = Migrate()
CACHE = Cache()
DEBUG = DebugToolbarExtension()
AUTH = GraphQLAuth()
# Static assets are not accessed by flask.
app = Flask(__name__, static_url_path=None, static_folder='/tmp')

app.secret_key = SECRET_KEY

app.config.from_object('config.settings')
app.url_map.strict_slashes = True

app.config['JWT_ACCESS_TOKEN_EXPIRES'] = datetime.timedelta(
    minutes=JWT_ACCESS_TOKEN_MINUTES)
app.config['JWT_REFRESH_TOKEN_EXPIRES'] = datetime.timedelta(
    days=JWT_REFRESH_TOKEN_DAYS)
app.config['JWT_HEADER_NAME'] = 'X-Access-Token'
app.config['JWT_HEADER_TYPE'] = ''

graphql_auth = GraphQLAuth(app)

app.config['SECRET_KEY'] = SECRET_KEY

# Both global and local sessions are used. Local sessions are read-write.
engine = create_engine(SQLALCHEMY_DATABASE_URI,
                       pool_size=SQLALCHEMY_POOL_SIZE,
                       isolation_level="AUTOCOMMIT")
DBSession = scoped_session(
    sessionmaker(autocommit=True, autoflush=True, bind=engine))


class ScopedSession(object):
    '''
    Use this for local session scope.
    Usage:
Exemple #13
0
from flask_bcrypt import Bcrypt
from flask_graphql_auth import GraphQLAuth
from flask_jwt_extended import JWTManager

bcrypt = Bcrypt()
auth = GraphQLAuth()
jwt = JWTManager()