-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp2.py
36 lines (26 loc) · 1.11 KB
/
app2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# application suitable for the documentation example
import FlaskSimpleAuth as fsa
import secret
def create_app():
app = fsa.Flask("app", FSA_MODE="dev", FSA_AUTH=["basic", "param", "none"])
# app password, group and other data
PASSDB = {login:app.hash_password(pw) for login, pw in secret.PASSES.items()}
ADMIN = {"calvin", "susie"}
HELLO = {"en": "Hello", "fr": "Bonjour", "de": "Guten Tag"}
# minimal authentication and authorization configuration
app.get_user_pass(PASSDB.get)
app.group_check("admin", ADMIN.__contains__)
# 4 routes
@app.get("/open", authz="OPEN")
def get_no_auth(lang: fsa.Cookie = "de"):
return fsa.jsonify(HELLO.get(lang, "Hey"))
@app.get("/authenticated", authz="AUTH")
def get_authenticated(user: fsa.CurrentUser, lang: fsa.Cookie = "de"):
return fsa.jsonify(HELLO.get(lang, "Hey") + " " + user)
@app.get("/only-admin", authz="admin")
def get_only_admin():
return fsa.jsonify("Salut administrateur !")
@app.get("/add", authz="OPEN")
def get_add(i: int, j: int):
return {"sum": i + j}
return app