Skip to content

Instantly share code, notes, and snippets.

@raghothams
Created February 22, 2016 10:10
Show Gist options
  • Save raghothams/b96f7770c32086743aac to your computer and use it in GitHub Desktop.
Save raghothams/b96f7770c32086743aac to your computer and use it in GitHub Desktop.
Flask request header decorator
from functools import wraps
from flask import Flask, request
app = Flask(__name__)
key = "ya29.bwLu0ruxXdXe_RMOSYgfiCPORNMHLkf9rCDmV1rKtWu90TuF1d8B2SmdUlrjeOWNYThkgMM"
def secure(f):
@wraps(f)
def check_authorization(*args, **kwargs):
if request.headers.get("Authorization") == key:
return f()
else:
return "lol"
return check_authorization
@app.route("/")
@secure
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(debug=True)
@AlexanderButyaev
Copy link

To be precise - it's recommended to return f(*args, **kwargs)...

@farmhutsoftwareteam
Copy link

ideally, where would one store this key, is it dynamic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment