4
4
import secret
5
5
6
6
# create application with token, param and basic authentication
7
- app = fsa .Flask ("app" , FSA_MODE = "dev" , FSA_AUTH = ["token" , "param" , "basic" , "none" ])
7
+ app = fsa .Flask (
8
+ "app" ,
9
+ FSA_MODE = "dev" ,
10
+ FSA_AUTH = ["token" , "param" , "basic" , "none" ],
11
+ )
8
12
9
13
# authentication with randomly-generated passwords
10
- PASSDB : dict [str , str ] = {login : app .hash_password (pwd ) for login , pwd in secret .PASSES .items ()}
14
+ PASSDB : dict [str , str ] = {
15
+ login : app .hash_password (pwd ) for login , pwd in secret .PASSES .items ()
16
+ }
11
17
app .get_user_pass (PASSDB .get )
12
18
13
19
# admin group authorization
14
20
ADMINS : set [str ] = {"calvin" , "susie" }
15
21
app .group_check ("ADMIN" , ADMINS .__contains__ )
16
22
17
23
# login routes
18
- @app .get ("/login" , authorize = "AUTH" , auth = "basic" )
24
+ @app .get ("/login" , authz = "AUTH" , authn = "basic" )
19
25
def get_login (user : fsa .CurrentUser ):
20
26
return {"user" : user , "token" : app .create_token (user )}, 200
21
27
22
- @app .post ("/login" , authorize = "AUTH" , auth = "param" )
28
+ @app .post ("/login" , authz = "AUTH" , authn = "param" )
23
29
def post_login (user : fsa .CurrentUser ):
24
30
return {"user" : user , "token" : app .create_token (user )}, 201
25
31
26
32
# identity routes
27
- @app .get ("/who-am-i" , authorize = "AUTH" )
33
+ @app .get ("/who-am-i" , authz = "AUTH" )
28
34
def get_who_am_i (user : fsa .CurrentUser , lang : fsa .Cookie = None ):
29
35
return {"user" : user , "isadmin" : user in ADMINS , "lang" : lang }, 200
30
36
31
- @app .get ("/admin" , authorize = "ADMIN" )
37
+ @app .get ("/admin" , authz = "ADMIN" )
32
38
def get_admin (user : fsa .CurrentUser ):
33
39
return {"user" : user , "isadmin" : True }, 200
34
40
35
41
# incredible open service for top-notch translations
36
42
HELLO = {"it" : "Ciao" , "fr" : "Salut" , "en" : "Hi" , "ko" : "안녕" }
37
43
38
- @app .get ("/hello" , authorize = "OPEN" )
44
+ @app .get ("/hello" , authz = "OPEN" )
39
45
def get_hello (lang : fsa .Cookie = "en" ):
40
46
return {"lang" : lang , "hello" : HELLO .get (lang , "Hi" )}, 200
41
47
@@ -45,34 +51,34 @@ def get_hello(lang: fsa.Cookie = "en"):
45
51
import model
46
52
47
53
# FIXME could we drop fsa.jsonify?
48
- @app .get ("/t0" , authorize = "OPEN" )
54
+ @app .get ("/t0" , authz = "OPEN" )
49
55
def get_t0 (t : fsa .JsonData ):
50
56
return fsa .jsonify (t )
51
57
52
- @app .post ("/t0" , authorize = "OPEN" )
58
+ @app .post ("/t0" , authz = "OPEN" )
53
59
def post_t0 (t : fsa .JsonData ):
54
60
return fsa .jsonify (t )
55
61
56
- @app .get ("/t1" , authorize = "OPEN" )
62
+ @app .get ("/t1" , authz = "OPEN" )
57
63
def get_t1 (t : model .Thing1 ):
58
64
return fsa .jsonify (t )
59
65
60
- @app .post ("/t1" , authorize = "OPEN" )
66
+ @app .post ("/t1" , authz = "OPEN" )
61
67
def post_t1 (t : model .Thing1 ):
62
68
return fsa .jsonify (t )
63
69
64
- @app .get ("/t2" , authorize = "OPEN" )
70
+ @app .get ("/t2" , authz = "OPEN" )
65
71
def get_t2 (t : model .Thing2 ):
66
72
return fsa .jsonify (t )
67
73
68
- @app .post ("/t2" , authorize = "OPEN" )
74
+ @app .post ("/t2" , authz = "OPEN" )
69
75
def post_t2 (t : model .Thing2 ):
70
76
return fsa .jsonify (t )
71
77
72
- @app .get ("/t3" , authorize = "OPEN" )
78
+ @app .get ("/t3" , authz = "OPEN" )
73
79
def get_t3 (t : model .Thing3 ):
74
80
return fsa .jsonify (t )
75
81
76
- @app .post ("/t3" , authorize = "OPEN" )
82
+ @app .post ("/t3" , authz = "OPEN" )
77
83
def post_t3 (t : model .Thing3 ):
78
84
return fsa .jsonify (t )
0 commit comments