the37lab-authlib 0.1.1751369506__py3-none-any.whl → 0.1.1751371611__py3-none-any.whl

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.
the37lab_authlib/auth.py CHANGED
@@ -17,6 +17,7 @@ logger = logging.getLogger(__name__)
17
17
 
18
18
  class AuthManager:
19
19
  def __init__(self, app=None, db_dsn=None, jwt_secret=None, oauth_config=None, id_type='integer', environment_prefix=None, api_tokens=None):
20
+ self.user_override = None
20
21
  if environment_prefix:
21
22
  prefix = environment_prefix.upper() + '_'
22
23
  db_dsn = os.getenv(f'{prefix}DATABASE_URL')
@@ -36,6 +37,11 @@ class AuthManager:
36
37
  if ':' in entry:
37
38
  key, user = entry.split(':', 1)
38
39
  api_tokens[key.strip()] = user.strip()
40
+ user_override_env = os.getenv(f'{prefix}USER_OVERRIDE')
41
+ if user_override_env:
42
+ self.user_override = user_override_env
43
+ if self.user_override and (api_tokens or db_dsn):
44
+ raise ValueError('Cannot set user_override together with api_tokens or db_dsn')
39
45
  if api_tokens and db_dsn:
40
46
  raise ValueError('Cannot set both api_tokens and db_dsn')
41
47
  self.api_tokens = api_tokens or None
@@ -131,6 +137,14 @@ class AuthManager:
131
137
  raise AuthError('Invalid token format')
132
138
 
133
139
  def _authenticate_request(self):
140
+ if self.user_override:
141
+ return {
142
+ 'id': self.user_override,
143
+ 'username': self.user_override,
144
+ 'email': '',
145
+ 'real_name': self.user_override,
146
+ 'roles': []
147
+ }
134
148
  auth_header = request.headers.get('Authorization')
135
149
  api_token = request.headers.get('X-API-Token')
136
150
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: the37lab_authlib
3
- Version: 0.1.1751369506
3
+ Version: 0.1.1751371611
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.
@@ -1,10 +1,10 @@
1
1
  the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
2
- the37lab_authlib/auth.py,sha256=1BDYWaxDFA_ND8hHg4V2r6mPkaG0c4TRcA9bJjL_A2o,22755
2
+ the37lab_authlib/auth.py,sha256=NKQ-k2QDB4ddw6QKO76RL5WeRpX2gNcpVr6VSHX2yrc,23358
3
3
  the37lab_authlib/db.py,sha256=fTXxnfju0lmbFGPVbXpTMeDmJMeBgURVZTndyxyRyCc,2734
4
4
  the37lab_authlib/decorators.py,sha256=L-gJUUwDUT2JXTptQ6XEey1LkI5RprbqzEfArWI7F8Y,1305
5
5
  the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
6
6
  the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
7
- the37lab_authlib-0.1.1751369506.dist-info/METADATA,sha256=F0RyaxHbxv3FIwm_OP3EjykaJVIlwgllcRxnWOqNITo,7686
8
- the37lab_authlib-0.1.1751369506.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- the37lab_authlib-0.1.1751369506.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
- the37lab_authlib-0.1.1751369506.dist-info/RECORD,,
7
+ the37lab_authlib-0.1.1751371611.dist-info/METADATA,sha256=J3mleZGwizcERDRBfrFnBW-21tTRh4nzfmWR575z3Bk,8319
8
+ the37lab_authlib-0.1.1751371611.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ the37lab_authlib-0.1.1751371611.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
+ the37lab_authlib-0.1.1751371611.dist-info/RECORD,,