source: src/mapservice/server_impl/security/Security.py@ 7be94aa

debian/bullseye
Last change on this file since 7be94aa was 7be94aa, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
  • Property mode set to 100644
File size: 1.3 KB
Line 
1'''
2 Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16'''
17from ..database.Model import ApiKey, User
18
19
20def auth_basic(username, password, required_scopes=None):
21 user = User.query.filter_by(username=username).all()
22 if len(user) != 1:
23 return None
24 if user[0].password_verify(password):
25 return {'sub': user[0].username}
26 return None
27
28
29def auth_api(apikey, required_scopes=None):
30 keys = ApiKey.query.filter_by(key=apikey).all()
31 if len(keys) != 1:
32 return None
33
34 key_db = keys[0]
35 if apikey == key_db.key:
36 return {'sub': key_db.user.username}
37
38 # optional: raise exception for custom error response
39 return None
Note: See TracBrowser for help on using the repository browser.