-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathsecurity_controller.mustache
More file actions
56 lines (46 loc) · 2.24 KB
/
security_controller.mustache
File metadata and controls
56 lines (46 loc) · 2.24 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{{#authMethods}}
{{#isOAuth}}
def info_from_{{name}}(token: str) -> dict:
"""
Validate and decode token.
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
'scope' or 'scopes' will be passed to scope validation function.
Should return None if token is invalid or does not allow access to called API.
"""
return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'}
def validate_scope_{{name}}(required_scopes: list[str], token_scopes: list[str]) -> bool:
""" Validate required scopes are included in token scope """
return set(required_scopes).issubset(set(token_scopes))
{{/isOAuth}}
{{#isApiKey}}
def info_from_{{name}}(api_key: str, required_scopes: None) -> dict:
"""
Check and retrieve authentication information from api_key.
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
Should return None if api_key is invalid or does not allow access to called API.
"""
return {'uid': 'user_id'}
{{/isApiKey}}
{{#isBasicBasic}}
def info_from_{{name}}(username: str, password: str, required_scopes: None) -> dict:
"""
Check and retrieve authentication information from basic auth.
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
Should return None if auth is invalid or does not allow access to called API.
"""
return {'uid': 'user_id'}
{{/isBasicBasic}}
{{#isBasicBearer}}
def info_from_{{name}}(token: str) -> dict:
"""
Check and retrieve authentication information from custom bearer token.
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
Should return None if auth is invalid or does not allow access to called API.
"""
return {'uid': 'user_id'}
{{/isBasicBearer}}
{{/authMethods}}