Example #1
0
    def setUp(self):
        app = Flask(__name__)
        app.config["TESTING"] = True
        app.config["HMAC_KEYS"] = {"a": "aa", "b": "bb"}
        self.hmac = Hmac(app)

        self.app = app.test_client()

        @app.route("/autodecorated")
        def autodecorated():
            return "autodecorated"

        @app.before_request
        def before_request():
            try:
                self.hmac.validate_signature(request)
            except HmacException:
                return abort(400)
Example #2
0
def create_app(disable_hmac=None):
    app = Flask(__name__)
    app.config["TESTING"] = True
    app.config["HMAC_KEY"] = "s3cr3tk3y"
    app.config["HMAC_KEYS"] = {"a": "f00", "b": "b4r"}
    if disable_hmac:
        app.config["HMAC_DISARM"] = disable_hmac
    hmac.init_app(app)

    @app.route("/no_auth_view")
    def no_auth_view():
        return "no_auth_view"

    @app.route("/hmac_auth_view", methods=["GET", "POST"])
    @hmac.auth()
    def hmac_auth_view():
        return "hmac_auth_view"

    @app.route("/only_view", methods=["GET", "POST"])
    @hmac.auth(only=["b"])
    def only_view():
        return "hmac_auth_view"

    return app