-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
32 lines (24 loc) · 955 Bytes
/
auth.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
from flask_basicauth import BasicAuth
from flask import request
class Auth(BasicAuth):
def __init__(self, app, users_conf):
""" Takes a Flask app and a string of users and passwords formatted like this:
user1:password1,user2:password2,...
Used like this:
auth = Auth(app, "...")
@app.route("/something")
@auth.required
def something():
"""
super(Auth, self).__init__(app)
self.users = {}
for user_conf in users_conf.split(','):
(user, password) = user_conf.split(':')
self.users[user] = password
def check_credentials(self, username, password):
match = self.users.get(username) == password
if match:
request.current_user = username
else:
request.current_user = None
return match is True