debian/bullseye
|
Last change
on this file since 3db3d13 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
|
| Rev | Line | |
|---|
| [78abfaa] | 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 | '''
|
|---|
| [3a89adb] | 17 | from ..database.Model import ApiKey, User
|
|---|
| 18 |
|
|---|
| [7be94aa] | 19 |
|
|---|
| [3a89adb] | 20 | def auth_basic(username, password, required_scopes=None):
|
|---|
| [7be94aa] | 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 |
|
|---|
| [3a89adb] | 28 |
|
|---|
| 29 | def auth_api(apikey, required_scopes=None):
|
|---|
| [7be94aa] | 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.