Created
May 29, 2016 13:05
-
-
Save silviud/8a8c9e86f344a3d67194a41c7b758d3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 flask import Flask | |
from flask_hmacauth import ( | |
hmac_auth, | |
DictAccountBroker, | |
HmacManager | |
) | |
app = Flask(__name__) | |
accountmgr = DictAccountBroker( | |
accounts={ | |
"admin": {"secret": "secret", "rights": ["create", "edit", "delete", "view"]}, | |
"editor": {"secret": "secret", "rights": ["create", "edit", "view"]}, | |
"guest": {"secret": "secret", "rights": ["view"]} | |
}) | |
hmacmgr = HmacManager(accountmgr, app) | |
@app.route('/', methods=['GET']) | |
@hmac_auth('view') | |
def view(): | |
return "view" | |
@app.route('/', methods=['POST']) | |
@hmac_auth('create') | |
def create(): | |
return "Create" | |
@app.route('/', methods=['PUT']) | |
@hmac_auth('edit') | |
def edit(): | |
return "Edit" | |
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