Пример #1
0
def setup_app():
    """Setup OAuth2 provider."""
    # Initialize OAuth2 provider
    oauth2.init_app(current_app)

    # Configures the OAuth2 provider to use the SQLALchemy models for getters
    # and setters for user, client and tokens.
    bind_sqlalchemy(oauth2, db.session, client=Client)

    # Flask-OAuthlib does not support CACHE_REDIS_URL
    if cfg['OAUTH2_CACHE_TYPE'] == 'redis' and \
       cfg.get('CACHE_REDIS_URL'):
        from redis import from_url as redis_from_url
        cfg.setdefault(
            'OAUTHLIB_CACHE_REDIS_HOST',
            redis_from_url(cfg['CACHE_REDIS_URL'])
        )

    # Configures an OAuth2Provider instance to use configured caching system
    # to get and set the grant token.
    bind_cache_grant(current_app, oauth2, OAuthUserProxy.get_current_user)

    # Disables oauthlib's secure transport detection in in debug mode.
    if current_app.debug or current_app.testing:
        os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
Пример #2
0
def sqlalchemy_provider(app):
    oauth = OAuth2Provider(app)

    bind_sqlalchemy(oauth, db.session, user=User, token=Token,
                    client=Client, grant=Grant, current_user=current_user)

    return oauth
Пример #3
0
def sqlalchemy_provider(app):
    oauth = OAuth2Provider(app)

    bind_sqlalchemy(oauth, db.session, user=User, token=Token,
                    client=Client, grant=Grant, current_user=current_user)

    return oauth
Пример #4
0
    def __init__(self, app, entry_point_group=None):
        """Initialize state."""
        self.app = app
        self.scopes = {}

        # Initialize OAuth2 provider
        oauth2.init_app(app)

        # Configures the OAuth2 provider to use the SQLALchemy models for
        # getters and setters for user, client and tokens.
        bind_sqlalchemy(oauth2, db.session, client=Client)

        # Flask-OAuthlib does not support CACHE_REDIS_URL
        if app.config['OAUTH2_CACHE_TYPE'] == 'redis' and app.config.get(
                'CACHE_REDIS_URL'):
            from redis import from_url as redis_from_url
            app.config.setdefault(
                'OAUTH2_CACHE_REDIS_HOST',
                redis_from_url(app.config['CACHE_REDIS_URL']))

        # Configures an OAuth2Provider instance to use configured caching
        # system to get and set the grant token.
        bind_cache_grant(app, oauth2, lambda: OAuthUserProxy(current_user))

        # Disables oauthlib's secure transport detection in in debug mode.
        if app.debug or app.testing:
            os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

        if entry_point_group:
            self.load_entry_point_group(entry_point_group)
Пример #5
0
    def __init__(self, app, entry_point_group=None):
        """Initialize state."""
        self.app = app
        self.scopes = {}

        # Initialize OAuth2 provider
        oauth2.init_app(app)

        # Configures the OAuth2 provider to use the SQLALchemy models for
        # getters and setters for user, client and tokens.
        bind_sqlalchemy(oauth2, db.session, client=Client)

        # Flask-OAuthlib does not support CACHE_REDIS_URL
        if app.config['OAUTH2_CACHE_TYPE'] == 'redis' and app.config.get(
                'CACHE_REDIS_URL'):
            from redis import from_url as redis_from_url
            app.config.setdefault(
                'OAUTH2_CACHE_REDIS_HOST',
                redis_from_url(app.config['CACHE_REDIS_URL'])
            )

        # Configures an OAuth2Provider instance to use configured caching
        # system to get and set the grant token.
        bind_cache_grant(app, oauth2, lambda: OAuthUserProxy(current_user))

        # Disables oauthlib's secure transport detection in in debug mode.
        if app.debug or app.testing:
            os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

        if entry_point_group:
            self.load_entry_point_group(entry_point_group)
Пример #6
0
def setup_app():
    """
    Setup OAuth2 provider
    """
    # Initialize OAuth2 provider
    oauth2.init_app(current_app)

    # Register default scopes (note, each module will)
    for scope, options in current_app.config['OAUTH2_DEFAULT_SCOPES'].items():
        if scope not in scopes:
            scopes.register(Scope(scope, options))

    # Configures the OAuth2 provider to use the SQLALchemy models for getters
    # and setters for user, client and tokens.
    bind_sqlalchemy(oauth2, db.session, client=OAuthClient)

    # Configures an OAuth2Provider instance to use configured caching system
    # to get and set the grant token.
    bind_cache_grant(current_app, oauth2, OAuthUserProxy.get_current_user)

    for x in ['oauthlib', 'flask_oauthlib']:
        logger = logging.getLogger('flask_oauthlib')
        logger.setLevel(current_app.logger.getEffectiveLevel())
        for h in current_app.logger.handlers:
            if h not in logger.handlers:
                logger.addHandler(h)
Пример #7
0
def setup_app():
    """
    Setup OAuth2 provider
    """
    # Initialize OAuth2 provider
    oauth2.init_app(current_app)

    # Register default scopes (note, each module will)
    for scope, options in current_app.config['OAUTH2_DEFAULT_SCOPES'].items():
        if scope not in scopes:
            scopes.register(Scope(scope, options))

    # Configures the OAuth2 provider to use the SQLALchemy models for getters
    # and setters for user, client and tokens.
    bind_sqlalchemy(oauth2, db.session, client=OAuthClient)

    # Configures an OAuth2Provider instance to use configured caching system
    # to get and set the grant token.
    bind_cache_grant(current_app, oauth2, OAuthUserProxy.get_current_user)
    
    for x in ['oauthlib', 'flask_oauthlib']:
        logger = logging.getLogger('flask_oauthlib')
        logger.setLevel(current_app.logger.getEffectiveLevel())
        for h in current_app.logger.handlers:
            if h not in logger.handlers:
                logger.addHandler(h)
Пример #8
0
def cache_provider(app):
    bind_sqlalchemy(oauth, db.session, user=User,
                    token=Token, client=Client)

    app.config.update({'OAUTH2_CACHE_TYPE': 'simple'})
    bind_cache_grant(app, oauth, current_user)
    return oauth
Пример #9
0
def create_app(config=None):
    app = Flask('tbapi')

    app.config.update(
        dict(Debug=True,
             SQLALCHEMY_DATABASE_URI=
             'mysql+pymysql://tbapi:tbapi@app-db:3306/tbapi',
             SQLALCHEMY_TRACK_MODIFICATIONS=False,
             SQLALCHEMY_POOL_RECYCLE=60,
             SQLALCHEMY_BINDS={
                 'mpower':
                 'mysql+pymysql://mpower:mpower@mpower-db:3306/mpower_demo',
             }))

    CORS(app)

    #app.config.update(config or {})
    app.config.from_envvar('TBAPI_SETTINGS', silent=True)

    app.secret_key = '12345678'

    from tbapi.db import db
    db.init_app(app)

    from tbapi.bcrypt import bcrypt
    bcrypt.init_app(app)

    # Reflect only the structure of the mPOWEr db.
    with app.app_context():
        db.reflect(bind='mpower')

    from tbapi.models import Patient, MpowerUser

    from tbapi.blueprints.api import api
    from tbapi.blueprints.static import static
    from tbapi.blueprints.oauth import oauth

    app.register_blueprint(api, url_prefix='/api/v1.0')
    app.register_blueprint(static, url_prefix='')
    app.register_blueprint(oauth, url_prefix='/oauth')

    oauth2.init_app(app)
    bind_sqlalchemy(oauth2,
                    db.session,
                    user=User,
                    token=Token,
                    client=Client,
                    grant=Grant,
                    current_user=current_user)

    # register_cli(app)
    # register_teardowns(app)

    # @app.before_request
    # def load_current_user():
    #     user = User.query.get(1)
    #     g.user = user

    return app
Пример #10
0
def cache_provider(app):
    oauth = OAuth2Provider(app)

    bind_sqlalchemy(oauth, db.session, user=Fhiruser, token=Token, client=Client)

    app.config.update({"OAUTH2_CACHE_TYPE": "simple"})
    bind_cache_grant(app, oauth, current_user)
    return oauth
Пример #11
0
def cache_provider(app):
    oauth = OAuth2Provider(app)

    bind_sqlalchemy(oauth, db.session, user=User, token=Token, client=Client)

    app.config.update({"OAUTH2_CACHE_TYPE": "simple"})
    bind_cache_grant(app, oauth, current_user)
    return oauth
Пример #12
0
def setup_app():
    """
    Setup OAuth2 provider
    """
    # Initialize OAuth2 provider
    oauth2.init_app(current_app)

    # Register default scopes (note, each module will)
    for scope, options in current_app.config['OAUTH2_DEFAULT_SCOPES'].items():
        if scope not in scopes:
            scopes.register(scope, options)

    # Configures the OAuth2 provider to use the SQLALchemy models for getters
    # and setters for user, client and tokens.
    bind_sqlalchemy(oauth2, db.session, client=Client)

    # Configures an OAuth2Provider instance to use configured caching system
    # to get and set the grant token.
    bind_cache_grant(current_app, oauth2, OAuthUserProxy.get_current_user)
Пример #13
0
#     access_token_url='https://www.google.com/o/oauth2/token',
#     access_token_method='POST',
#     access_token_params={'grant_type': 'authorization_code'},
#     consumer_key=GOOGLE_CLIENT_ID,
#     consumer_secret=GOOGLE_CLIENT_SECRET
#     )


@lm.user_loader
def load_user(id):
    return User.query.get(int(id))
    # user = ?
    # TODO: g.user = ? read documentation for flask-login manager


bind_sqlalchemy(oauth, db.session, user=User, token=Token, client=Client)
app.config.update({'OAUTH2_CACHE_TYPE': 'simple'})  # need to move to config.py
# bind_cache_grant(app, oauth, g.user)  # need to read into params and config


@app.before_request
def before_request():
    g.user = current_user


@app.route('/')
@app.route('/index')
def index():
    user = g.user
    posts = [  # fake array of posts
        {
Пример #14
0
# import dependencies
from flask_login import current_user
from flask_oauthlib.provider import OAuth2Provider
from flask_oauthlib.contrib.oauth2 import bind_cache_grant, bind_sqlalchemy

from extranet import app, db
from extranet.models.user import User
from extranet.models.oauth import OauthApp, OauthToken

# configure oauth provider
provider = OAuth2Provider(app)

# configure stores
bind_sqlalchemy(provider,
                db.session,
                user=User,
                client=OauthApp,
                token=OauthToken)


def current_user_func():
    return User.query.get(current_user.id)


bind_cache_grant(app, provider, current_user_func)

scopes = {
    'user.read': {
        'description_brief':
        "Read your profile",
        'description':
Пример #15
0
def create_app(config_file=None):
    app = Flask('app')

    AppConfig(app, config_file)

    SSLify(app)

    stream = logging.StreamHandler()
    stream.setFormatter(logging.Formatter(
        '%(name)s %(levelname)s %(asctime)s "%(message)s"'
    ))
    admin_logger = logging.getLogger('app.admin')
    admin_logger.setLevel(logging.INFO)
    admin_logger.addHandler(stream)

    db.app = app
    db.init_app(app)

    bootstrap.app = app
    bootstrap.init_app(app)

    nav.app = app
    nav.register_element('top', get_navbar)
    register_renderer(app, 'twoside', TwoSideRenderer)
    nav.init_app(app)

    login_manager.app = app
    login_manager.init_app(app)

    mail.app = app
    mail.init_app(app)

    cache.app = app
    cache.init_app(app)

    oauth.app = app
    oauth.init_app(app)
    bind_sqlalchemy(oauth, db.session,
                    user=User,
                    client=oauth2.Client,
                    token=oauth2.Token,
                    grant=oauth2.Grant,
                    current_user=lambda: current_user)

    if not app.debug:
        sentry.app = app
        sentry.init_app(app)

    admin.app = app
    admin.init_app(app)
    admin.add_view(AdAdminView(Ad, db.session))
    admin.add_view(LinkAdminView(Link, db.session))
    admin.add_view(trial.TrialEmailAdminView(trial.TrialEmail, db.session))

    #celery.app = app
    #celery.init_app(app)

    user_manager.init_app(
        app,
        db_adapter=SQLAlchemyAdapter(db, User, UserInvitationClass=UserInvitation),
        login_manager=login_manager
    )

    gravatar.app = app
    gravatar.init_app(app)

    api_manager.app = app
    api_manager.init_app(app)

    app.register_blueprint(trial.bp, url_prefix='/trial')
    app.register_blueprint(oauth2.view.bp, url_prefix='/oauth')
    app.register_blueprint(social.bp, url_prefix='/social')
    app.register_blueprint(dashboard.bp, url_prefix='/dashboard')
    app.register_blueprint(share.bp, url_prefix='/share')
    app.register_blueprint(web.bp)

    for jinja_filter in FILTERS:
        app.jinja_env.filters[jinja_filter] = FILTERS[jinja_filter]
    for jinja_test in TESTS:
        app.jinja_env.tests[jinja_test] = TESTS[jinja_test]

    return app