-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
28 lines (24 loc) · 662 Bytes
/
auth.py
File metadata and controls
28 lines (24 loc) · 662 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
25
26
27
28
#!/usr/bin/env python3.6
from flask import make_response, jsonify
from flask_httpauth import HTTPBasicAuth
auth = HTTPBasicAuth()
# Dummy users for auth, only form demo purpose
users = {
"user1": "password1",
"user2": "password2",
"user3": "password3"
}
@auth.get_password
def get_password(username):
'''
Function auth for basich auth mapping username and password, dummy only for demo purpose
'''
if username in users:
return users.get(username)
return None
@auth.error_handler
def unauthorized():
'''
Function error handler 401
'''
return make_response(jsonify({'error': 'Unauthorized access'}), 401)