-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsecurity.py
More file actions
24 lines (19 loc) · 940 Bytes
/
security.py
File metadata and controls
24 lines (19 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from liteapi import liteapi,BaseAPIRequest,APIAuth
from liteapi.security import RequireBasicAuth, RequireOAuth2PasswordAuth, RequireOAuth2Token
app = liteapi()
@app.register('/basic')
class rootMethod (BaseAPIRequest):
@RequireBasicAuth(checkerFunc=lambda username, password: username=="user" and password=="secret")
def get(self, auth:APIAuth):
return {'message': f'Thank you {auth.username} for using liteapi'}
@app.register('/token')
class rootMethod (BaseAPIRequest):
@RequireOAuth2PasswordAuth(checkerFunc=lambda username, password: username=="user" and password=="secret")
def post(self):
return {'access_token': 'mytoken', 'token_type': 'Bearer'}
@app.register('/OAuth')
class rootMethod (BaseAPIRequest):
@RequireOAuth2Token(checkerFunc=lambda access_token: access_token == 'mytoken', token_url='token')
def get(self):
return {'message': f'Thank you for using liteapi'}
app.run()