source: src/mapservice/server_impl/security/Security.py@ ff880df

debian/bullseye
Last change on this file since ff880df was ae2ff15, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Fixed testing environment
    • Fixed some issues in the API and it's serving
  • 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
19def auth_basic(username, password, required_scopes=None):
20 user = User.query.filter_by(username=username).all()
21 if len(user) != 1:
22 return None
23 if user[0].password_verify(password):
24 return {'sub': user[0].username}
25 return None
26
27def auth_api(apikey, required_scopes=None):
28 keys = ApiKey.query.filter_by(key=apikey).all()
29 if len(keys) != 1:
30 return None
31
32 key_db = keys[0]
33 if apikey == key_db.key:
34 return {'sub': key_db.user.username }
35
36 # optional: raise exception for custom error response
37 return None
Note: See TracBrowser for help on using the repository browser.