def create_app(**kwargs_config): app = factory.create_app(app_name=__name__.replace(".app", ""), **kwargs_config) api = Api(app) # Overwrite WWW-Authenticate challenge on 401 api.unauthorized = lambda noop: noop CORS( app, origins=app.config.get("CORS_DOMAINS"), allow_headers=app.config.get("CORS_HEADERS"), methods=app.config.get("CORS_METHODS"), ) app.json_encoder = JSONEncoder api.add_resource(StatusView, "/status") api.add_resource(ProtectedView, "/protected") api.add_resource(UserResolver, "/user/<string:identifier>") discover(app) # Incorporate local and remote applications into this one # Register custom error handlers if not app.config.get("DEBUG"): app.errorhandler(AdsWSError)(on_adsws_error) app.errorhandler(AdsWSFormError)(on_adsws_form_error) return app
def create_app(**kwargs_config): app = factory.create_app( app_name=__name__.replace('.app', ''), **kwargs_config ) api = Api(app) # Overwrite WWW-Authenticate challenge on 401 api.unauthorized = lambda noop: noop CORS( app, origins=app.config.get('CORS_DOMAINS'), allow_headers=app.config.get('CORS_HEADERS'), methods=app.config.get('CORS_METHODS') ) app.json_encoder = JSONEncoder api.add_resource(BenchmarkEndView, '/end') api.add_resource(BenchmarkRedirectView, '/redirect') api.add_resource(BenchmarkDoubleRedirectView, '/double_redirect') api.add_resource(BenchmarkTimeoutEndView, '/timeout_end') api.add_resource(BenchmarkTimeoutRedirectView, '/timeout_redirect') # Register custom error handlers if not app.config.get('DEBUG'): app.errorhandler(AdsWSError)(on_adsws_error) app.errorhandler(AdsWSFormError)(on_adsws_form_error) return app
def create_app(**kwargs_config): app = factory.create_app(app_name=__name__.replace('.app', ''), **kwargs_config) api = Api(app) # Overwrite WWW-Authenticate challenge on 401 api.unauthorized = lambda noop: noop CORS(app, origins=app.config.get('CORS_DOMAINS'), allow_headers=app.config.get('CORS_HEADERS'), methods=app.config.get('CORS_METHODS')) app.json_encoder = JSONEncoder api.add_resource(StatusView, '/status') api.add_resource(ProtectedView, '/protected') api.add_resource(UserResolver, '/user/<string:identifier>') discover(app) # Incorporate local and remote applications into this one # Register custom error handlers if not app.config.get('DEBUG'): app.errorhandler(AdsWSError)(on_adsws_error) app.errorhandler(AdsWSFormError)(on_adsws_form_error) return app
def create_app(**kwargs_config): """ Create the flask app :param kwargs_config: overwrite any base level config :return: flask.Flask instance """ app = factory.create_app(app_name=__name__.replace('.app', ''), **kwargs_config) api = Api(app) api.unauthorized = lambda noop: noop #Overwrite WWW-Authenticate challenge on 401 csrf = CsrfProtect(app) mail = Mail(app) cors = CORS( app, origins=app.config.get('CORS_DOMAINS'), allow_headers=app.config.get('CORS_HEADERS'), methods=app.config.get('CORS_METHODS'), supports_credentials=True, ) app.json_encoder = JSONEncoder api.add_resource(Bootstrap, '/bootstrap') api.add_resource(StatusView, '/status') api.add_resource(OAuthProtectedView, '/protected') api.add_resource(CSRFView, '/csrf') api.add_resource(UserAuthView, '/user') api.add_resource(DeleteAccountView, '/user/delete') api.add_resource(UserRegistrationView, '/register') api.add_resource(LogoutView, '/logout') api.add_resource(PersonalTokenView, '/token') api.add_resource(ChangePasswordView, '/change-password') api.add_resource(ChangeEmailView, '/change-email') api.add_resource(VerifyEmailView, '/verify/<string:token>') api.add_resource(ForgotPasswordView, '/reset-password/<string:token>') app.ts = URLSafeTimedSerializer(app.config["SECRET_KEY"]) @app.login_manager.unauthorized_handler def unauthorized(): """ flask_login callback when @login_required is not met. This overrides the default behavior or re-directing to a login view """ abort(401) # Register custom error handlers if not app.config.get('DEBUG'): app.errorhandler(AdsWSError)(on_adsws_error) app.errorhandler(AdsWSFormError)(on_adsws_form_error) @csrf.error_handler def csrf_error(reason): app.logger.warning("CSRF Blocked: {reason}".format(reason=reason)) return jsonify(dict(error="Invalid CSRF token")), 400 return app
def create_app(**kwargs_config): """ Create the flask app :param kwargs_config: overwrite any base level config :return: flask.Flask instance """ app = factory.create_app( app_name=__name__.replace('.app', ''), **kwargs_config ) api = Api(app) api.unauthorized = lambda noop: noop #Overwrite WWW-Authenticate challenge on 401 csrf = CsrfProtect(app) mail = Mail(app) cors = CORS(app, origins=app.config.get('CORS_DOMAINS'), allow_headers=app.config.get('CORS_HEADERS'), methods=app.config.get('CORS_METHODS'), supports_credentials=True, ) app.json_encoder = JSONEncoder api.add_resource(Bootstrap, '/bootstrap') api.add_resource(StatusView, '/status') api.add_resource(OAuthProtectedView, '/protected') api.add_resource(CSRFView, '/csrf') api.add_resource(UserAuthView, '/user') api.add_resource(DeleteAccountView, '/user/delete') api.add_resource(UserRegistrationView, '/register') api.add_resource(LogoutView, '/logout') api.add_resource(PersonalTokenView, '/token') api.add_resource(ChangePasswordView, '/change-password') api.add_resource(ChangeEmailView, '/change-email') api.add_resource(VerifyEmailView, '/verify/<string:token>') api.add_resource(ForgotPasswordView, '/reset-password/<string:token>') app.ts = URLSafeTimedSerializer(app.config["SECRET_KEY"]) @app.login_manager.unauthorized_handler def unauthorized(): """ flask_login callback when @login_required is not met. This overrides the default behavior or re-directing to a login view """ abort(401) # Register custom error handlers if not app.config.get('DEBUG'): app.errorhandler(AdsWSError)(on_adsws_error) app.errorhandler(AdsWSFormError)(on_adsws_form_error) @csrf.error_handler def csrf_error(reason): app.logger.warning("CSRF Blocked: {reason}".format(reason=reason)) return jsonify(dict(error="Invalid CSRF token")), 400 return app
def new_restful_api(blueprint): """ Flask-Restful asks for authentication on 401 error through http basic-auth. Since we're not using http basic-auth, we have to disable this default handler. :param blueprint: :return: """ api = Api(blueprint) api.unauthorized = _unauthorized_override return api
def new_restful_api(blueprint): """ Flask-Restful asks for authentication on 401 error through http basic-auth. Since we're not using http basic-auth, we have to disable this default handler. :param blueprint: :return: """ api = Api(blueprint) api.unauthorized = _unauthorized_override return api
def create_app(resources={}, **kwargs_config): app = factory.create_app(app_name=__name__.replace('.app', ''), **kwargs_config) app.config['resources'] = resources api = Api(app) # Overwrite WWW-Authenticate challenge on 401 api.unauthorized = lambda noop: noop api.add_resource(StatusView, '/', endpoint="root_statusview") api.add_resource(StatusView, '/status') api.add_resource(GlobalResourcesView, '/resources') return app
def create_app(resources={}, **kwargs_config): app = factory.create_app( app_name=__name__.replace('.app', ''), **kwargs_config ) app.config['resources'] = resources api = Api(app) # Overwrite WWW-Authenticate challenge on 401 api.unauthorized = lambda noop: noop api.add_resource(StatusView, '/', endpoint="root_statusview") api.add_resource(StatusView, '/status') api.add_resource(GlobalResourcesView, '/resources') return app
from flask import Blueprint, abort from flask.ext.restful import Api from flask.ext.cors import CORS api_v1 = Blueprint('api_v1', __name__) CORS(api_v1) api = Api(api_v1, prefix="/api/v1") #override api unautherized function def unauth(resp): return resp api.unauthorized = unauth ''' def authenticated(func): @wraps(func) def wrapper(*args, **kwargs): if current_user.is_anonymous(): abort(401, 'Access denied!!!!') return func(*args, **kwargs) return wrapper ''' from . import login from . import users from . import app
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.restful import Api from flask_oauthlib.provider import OAuth2Provider app = Flask(__name__, static_url_path='/static') app.config.from_object('config') db = SQLAlchemy(app, session_options={ 'expire_on_commit': False }) oauth = OAuth2Provider(app) oauth.init_app(app) api = Api(app) api.unauthorized = lambda a: a from zwayrest import restapi
from flask import Blueprint, abort from flask.ext.restful import Api from flask.ext.cors import CORS api_v1 = Blueprint('api_v1', __name__) CORS(api_v1) api = Api(api_v1, prefix="/api/v1") #override api unautherized function def unauth(resp): return resp api.unauthorized = unauth ''' def authenticated(func): @wraps(func) def wrapper(*args, **kwargs): if current_user.is_anonymous(): abort(401, 'Access denied!!!!') return func(*args, **kwargs) return wrapper ''' from . import login from . import users from . import app