Created
February 22, 2016 10:10
-
-
Save raghothams/b96f7770c32086743aac to your computer and use it in GitHub Desktop.
Flask request header decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ideally, where would one store this key, is it dynamic?