the37lab-authlib 0.1.1751369506__tar.gz → 0.1.1755164205__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of the37lab-authlib might be problematic. Click here for more details.
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/PKG-INFO +16 -1
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/README.md +15 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/pyproject.toml +1 -1
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/auth.py +21 -2
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib.egg-info/PKG-INFO +16 -1
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/setup.cfg +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/__init__.py +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/db.py +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/decorators.py +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/exceptions.py +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/models.py +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib.egg-info/SOURCES.txt +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib.egg-info/dependency_links.txt +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib.egg-info/requires.txt +0 -0
- {the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: the37lab_authlib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1755164205
|
|
4
4
|
Summary: Python SDK for the Authlib
|
|
5
5
|
Author-email: the37lab <info@the37lab.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -42,6 +42,9 @@ A Python authentication library that provides JWT, OAuth2, and API token authent
|
|
|
42
42
|
- [API Token Override for Testing](#api-token-override-for-testing)
|
|
43
43
|
- [Usage](#usage)
|
|
44
44
|
- [Warning](#warning)
|
|
45
|
+
- [User Override for Testing](#user-override-for-testing)
|
|
46
|
+
- [Usage](#usage-1)
|
|
47
|
+
- [Warning](#warning-1)
|
|
45
48
|
|
|
46
49
|
## Installation
|
|
47
50
|
|
|
@@ -233,3 +236,15 @@ For testing purposes, you can bypass the database and provide a static mapping o
|
|
|
233
236
|
Replace `MYAPP` with your environment prefix.
|
|
234
237
|
|
|
235
238
|
**Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
|
|
239
|
+
|
|
240
|
+
## User Override for Testing
|
|
241
|
+
|
|
242
|
+
For testing purposes, you can force all authentication to return a specific user by setting the `{PREFIX}USER_OVERRIDE` environment variable:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
export MYAPP_USER_OVERRIDE="testuser"
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
If set, all requests will be authenticated as the specified user, regardless of any tokens or credentials provided. This cannot be combined with `api_tokens` or `db_dsn`.
|
|
249
|
+
|
|
250
|
+
**Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
|
|
@@ -25,6 +25,9 @@ A Python authentication library that provides JWT, OAuth2, and API token authent
|
|
|
25
25
|
- [API Token Override for Testing](#api-token-override-for-testing)
|
|
26
26
|
- [Usage](#usage)
|
|
27
27
|
- [Warning](#warning)
|
|
28
|
+
- [User Override for Testing](#user-override-for-testing)
|
|
29
|
+
- [Usage](#usage-1)
|
|
30
|
+
- [Warning](#warning-1)
|
|
28
31
|
|
|
29
32
|
## Installation
|
|
30
33
|
|
|
@@ -216,3 +219,15 @@ For testing purposes, you can bypass the database and provide a static mapping o
|
|
|
216
219
|
Replace `MYAPP` with your environment prefix.
|
|
217
220
|
|
|
218
221
|
**Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
|
|
222
|
+
|
|
223
|
+
## User Override for Testing
|
|
224
|
+
|
|
225
|
+
For testing purposes, you can force all authentication to return a specific user by setting the `{PREFIX}USER_OVERRIDE` environment variable:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
export MYAPP_USER_OVERRIDE="testuser"
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
If set, all requests will be authenticated as the specified user, regardless of any tokens or credentials provided. This cannot be combined with `api_tokens` or `db_dsn`.
|
|
232
|
+
|
|
233
|
+
**Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "the37lab_authlib"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.1755164205"
|
|
8
8
|
description = "Python SDK for the Authlib"
|
|
9
9
|
authors = [{name = "the37lab", email = "info@the37lab.com"}]
|
|
10
10
|
dependencies = ["flask", "psycopg2-binary", "pyjwt", "python-dotenv", "requests", "authlib", "bcrypt"]
|
{the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/auth.py
RENAMED
|
@@ -11,12 +11,14 @@ import bcrypt
|
|
|
11
11
|
import logging
|
|
12
12
|
import os
|
|
13
13
|
from functools import wraps
|
|
14
|
+
from isodate import parse_duration
|
|
14
15
|
|
|
15
16
|
logging.basicConfig(level=logging.DEBUG)
|
|
16
17
|
logger = logging.getLogger(__name__)
|
|
17
18
|
|
|
18
19
|
class AuthManager:
|
|
19
20
|
def __init__(self, app=None, db_dsn=None, jwt_secret=None, oauth_config=None, id_type='integer', environment_prefix=None, api_tokens=None):
|
|
21
|
+
self.user_override = None
|
|
20
22
|
if environment_prefix:
|
|
21
23
|
prefix = environment_prefix.upper() + '_'
|
|
22
24
|
db_dsn = os.getenv(f'{prefix}DATABASE_URL')
|
|
@@ -36,6 +38,15 @@ class AuthManager:
|
|
|
36
38
|
if ':' in entry:
|
|
37
39
|
key, user = entry.split(':', 1)
|
|
38
40
|
api_tokens[key.strip()] = user.strip()
|
|
41
|
+
user_override_env = os.getenv(f'{prefix}USER_OVERRIDE')
|
|
42
|
+
if user_override_env:
|
|
43
|
+
self.user_override = user_override_env
|
|
44
|
+
else:
|
|
45
|
+
prefix = ''
|
|
46
|
+
|
|
47
|
+
self.expiry_time = parse_duration(os.getenv(f'{prefix}JWT_TOKEN_EXPIRY_TIME', 'PT1H'))
|
|
48
|
+
if self.user_override and (api_tokens or db_dsn):
|
|
49
|
+
raise ValueError('Cannot set user_override together with api_tokens or db_dsn')
|
|
39
50
|
if api_tokens and db_dsn:
|
|
40
51
|
raise ValueError('Cannot set both api_tokens and db_dsn')
|
|
41
52
|
self.api_tokens = api_tokens or None
|
|
@@ -131,6 +142,14 @@ class AuthManager:
|
|
|
131
142
|
raise AuthError('Invalid token format')
|
|
132
143
|
|
|
133
144
|
def _authenticate_request(self):
|
|
145
|
+
if self.user_override:
|
|
146
|
+
return {
|
|
147
|
+
'id': self.user_override,
|
|
148
|
+
'username': self.user_override,
|
|
149
|
+
'email': '',
|
|
150
|
+
'real_name': self.user_override,
|
|
151
|
+
'roles': []
|
|
152
|
+
}
|
|
134
153
|
auth_header = request.headers.get('Authorization')
|
|
135
154
|
api_token = request.headers.get('X-API-Token')
|
|
136
155
|
|
|
@@ -473,12 +492,12 @@ class AuthManager:
|
|
|
473
492
|
def _create_token(self, user):
|
|
474
493
|
payload = {
|
|
475
494
|
'sub': str(user['id']),
|
|
476
|
-
'exp': datetime.utcnow() +
|
|
495
|
+
'exp': datetime.utcnow() + self.expiry_time,
|
|
477
496
|
'iat': datetime.utcnow()
|
|
478
497
|
}
|
|
479
498
|
logger.debug(f"Creating token with payload: {payload}")
|
|
480
499
|
token = jwt.encode(payload, self.jwt_secret, algorithm='HS256')
|
|
481
|
-
logger.
|
|
500
|
+
logger.info(f"Created token: {token}")
|
|
482
501
|
return token
|
|
483
502
|
|
|
484
503
|
def _create_refresh_token(self, user):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: the37lab_authlib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1755164205
|
|
4
4
|
Summary: Python SDK for the Authlib
|
|
5
5
|
Author-email: the37lab <info@the37lab.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -42,6 +42,9 @@ A Python authentication library that provides JWT, OAuth2, and API token authent
|
|
|
42
42
|
- [API Token Override for Testing](#api-token-override-for-testing)
|
|
43
43
|
- [Usage](#usage)
|
|
44
44
|
- [Warning](#warning)
|
|
45
|
+
- [User Override for Testing](#user-override-for-testing)
|
|
46
|
+
- [Usage](#usage-1)
|
|
47
|
+
- [Warning](#warning-1)
|
|
45
48
|
|
|
46
49
|
## Installation
|
|
47
50
|
|
|
@@ -233,3 +236,15 @@ For testing purposes, you can bypass the database and provide a static mapping o
|
|
|
233
236
|
Replace `MYAPP` with your environment prefix.
|
|
234
237
|
|
|
235
238
|
**Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
|
|
239
|
+
|
|
240
|
+
## User Override for Testing
|
|
241
|
+
|
|
242
|
+
For testing purposes, you can force all authentication to return a specific user by setting the `{PREFIX}USER_OVERRIDE` environment variable:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
export MYAPP_USER_OVERRIDE="testuser"
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
If set, all requests will be authenticated as the specified user, regardless of any tokens or credentials provided. This cannot be combined with `api_tokens` or `db_dsn`.
|
|
249
|
+
|
|
250
|
+
**Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
|
|
File without changes
|
{the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/__init__.py
RENAMED
|
File without changes
|
{the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/db.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{the37lab_authlib-0.1.1751369506 → the37lab_authlib-0.1.1755164205}/src/the37lab_authlib/models.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|