コード例 #1
0
@verify_user
def private_scoped(user):
    """A valid access token and an appropriate scope are required to access this route
    """
    if requires_scope(config.auth0.scope):
        response = (
            "Hello from a private endpoint! You need to be authenticated and have a scope of "
            + config.auth0.scope
            + " to see this."
        )
        return jsonify(message=response)
    Log.error("You don't have access to {{scope}}", scope=config.auth0.scope, code=403)


add_flask_rule(APP, "/api/public", public)
add_flask_rule(APP, "/api/private", private)
add_flask_rule(APP, "/api/private-scoped", private_scoped)


config = startup.read_settings()
constants.set(config.constants)
Log.start(config.debug)

session_manager = setup_flask_session(APP, config.session)
perm = Permissions(Sqlite(config.permissions.store))
auth = Authenticator(APP, config.auth0, perm, session_manager)

Log.note("start servers")
setup_flask_ssl(APP, config.flask)
APP.run(**config.flask)
コード例 #2
0
        Log.error("Query is too large to parse")

    request_body = flask.request.get_data().strip()
    text = utf82unicode(request_body)
    data = json2value(text)

    try:
        record_request(flask.request, data, None, None)
    except Exception as e:
        Log.error("Problem processing request {{request}}")


if __name__ == "__main__":
    CONFIG = startup.read_settings()
    constants.set(CONFIG.constants)
    Log.start(CONFIG.debug)

    app = Flask(__name__,
                static_url_path="/public",
                static_folder="./public",
                root_path=".")
    app.secret_key = CONFIG.annotation.auth0.client.secret
    app.debug = True

    requires_auth, login, logout, callback = oauth.setup(
        app, CONFIG.annotation.auth0)

    app.add_url_rule("/", None, requires_auth(home))
    app.add_url_rule("/dashboard", None, requires_auth(dashboard))
    app.add_url_rule("/annotation", None, requires_auth(annotation))