the37lab-authlib 0.1.1751357568__tar.gz → 0.1.1751369506__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.

Files changed (15) hide show
  1. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/PKG-INFO +23 -1
  2. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/README.md +22 -0
  3. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/pyproject.toml +1 -1
  4. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib/auth.py +23 -1
  5. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib.egg-info/PKG-INFO +23 -1
  6. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/setup.cfg +0 -0
  7. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib/__init__.py +0 -0
  8. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib/db.py +0 -0
  9. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib/decorators.py +0 -0
  10. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib/exceptions.py +0 -0
  11. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib/models.py +0 -0
  12. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib.egg-info/SOURCES.txt +0 -0
  13. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib.egg-info/dependency_links.txt +0 -0
  14. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/src/the37lab_authlib.egg-info/requires.txt +0 -0
  15. {the37lab_authlib-0.1.1751357568 → the37lab_authlib-0.1.1751369506}/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.1751357568
3
+ Version: 0.1.1751369506
4
4
  Summary: Python SDK for the Authlib
5
5
  Author-email: the37lab <info@the37lab.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -39,6 +39,9 @@ A Python authentication library that provides JWT, OAuth2, and API token authent
39
39
  - [Setup](#setup)
40
40
  - [Database Setup](#database-setup)
41
41
  - [Running Tests](#running-tests)
42
+ - [API Token Override for Testing](#api-token-override-for-testing)
43
+ - [Usage](#usage)
44
+ - [Warning](#warning)
42
45
 
43
46
  ## Installation
44
47
 
@@ -211,3 +214,22 @@ python -m authlib.cli db init
211
214
  ```bash
212
215
  pytest
213
216
  ```
217
+
218
+ ## API Token Override for Testing
219
+
220
+ For testing purposes, you can bypass the database and provide a static mapping of API tokens to usernames using the `api_tokens` argument to `AuthManager` or the `{PREFIX}API_TOKENS` environment variable.
221
+
222
+ ### Usage
223
+
224
+ - **Constructor argument:**
225
+ ```python
226
+ AuthManager(api_tokens={"token1": "user1", "token2": "user2"})
227
+ ```
228
+ - **Environment variable:**
229
+ Set `{PREFIX}API_TOKENS` to a comma-separated list of `token:username` pairs, e.g.:
230
+ ```
231
+ export MYAPP_API_TOKENS="token1:user1,token2:user2"
232
+ ```
233
+ Replace `MYAPP` with your environment prefix.
234
+
235
+ **Warning:** This method is intended only for testing and development. Do not use this approach in production environments.
@@ -22,6 +22,9 @@ A Python authentication library that provides JWT, OAuth2, and API token authent
22
22
  - [Setup](#setup)
23
23
  - [Database Setup](#database-setup)
24
24
  - [Running Tests](#running-tests)
25
+ - [API Token Override for Testing](#api-token-override-for-testing)
26
+ - [Usage](#usage)
27
+ - [Warning](#warning)
25
28
 
26
29
  ## Installation
27
30
 
@@ -194,3 +197,22 @@ python -m authlib.cli db init
194
197
  ```bash
195
198
  pytest
196
199
  ```
200
+
201
+ ## API Token Override for Testing
202
+
203
+ For testing purposes, you can bypass the database and provide a static mapping of API tokens to usernames using the `api_tokens` argument to `AuthManager` or the `{PREFIX}API_TOKENS` environment variable.
204
+
205
+ ### Usage
206
+
207
+ - **Constructor argument:**
208
+ ```python
209
+ AuthManager(api_tokens={"token1": "user1", "token2": "user2"})
210
+ ```
211
+ - **Environment variable:**
212
+ Set `{PREFIX}API_TOKENS` to a comma-separated list of `token:username` pairs, e.g.:
213
+ ```
214
+ export MYAPP_API_TOKENS="token1:user1,token2:user2"
215
+ ```
216
+ Replace `MYAPP` with your environment prefix.
217
+
218
+ **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.1751357568"
7
+ version = "0.1.1751369506"
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"]
@@ -16,7 +16,7 @@ logging.basicConfig(level=logging.DEBUG)
16
16
  logger = logging.getLogger(__name__)
17
17
 
18
18
  class AuthManager:
19
- def __init__(self, app=None, db_dsn=None, jwt_secret=None, oauth_config=None, id_type='integer', environment_prefix=None):
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
20
  if environment_prefix:
21
21
  prefix = environment_prefix.upper() + '_'
22
22
  db_dsn = os.getenv(f'{prefix}DATABASE_URL')
@@ -29,6 +29,16 @@ class AuthManager:
29
29
  'client_id': google_client_id,
30
30
  'client_secret': google_client_secret
31
31
  }
32
+ api_tokens_env = os.getenv(f'{prefix}API_TOKENS')
33
+ if api_tokens_env:
34
+ api_tokens = {}
35
+ for entry in api_tokens_env.split(','):
36
+ if ':' in entry:
37
+ key, user = entry.split(':', 1)
38
+ api_tokens[key.strip()] = user.strip()
39
+ if api_tokens and db_dsn:
40
+ raise ValueError('Cannot set both api_tokens and db_dsn')
41
+ self.api_tokens = api_tokens or None
32
42
  self.db = Database(db_dsn, id_type=id_type) if db_dsn else None
33
43
  self.jwt_secret = jwt_secret
34
44
  self.oauth_config = oauth_config or {}
@@ -61,6 +71,18 @@ class AuthManager:
61
71
  return redirect_uri
62
72
 
63
73
  def _validate_api_token(self, api_token):
74
+ if self.api_tokens is not None:
75
+ username = self.api_tokens.get(api_token)
76
+ if not username:
77
+ raise AuthError('Invalid API token')
78
+ # Return a minimal user dict
79
+ return {
80
+ 'id': username,
81
+ 'username': username,
82
+ 'email': '',
83
+ 'real_name': username,
84
+ 'roles': []
85
+ }
64
86
  try:
65
87
  parsed = ApiToken.parse_token(api_token)
66
88
  with self.db.get_cursor() as cur:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: the37lab_authlib
3
- Version: 0.1.1751357568
3
+ Version: 0.1.1751369506
4
4
  Summary: Python SDK for the Authlib
5
5
  Author-email: the37lab <info@the37lab.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -39,6 +39,9 @@ A Python authentication library that provides JWT, OAuth2, and API token authent
39
39
  - [Setup](#setup)
40
40
  - [Database Setup](#database-setup)
41
41
  - [Running Tests](#running-tests)
42
+ - [API Token Override for Testing](#api-token-override-for-testing)
43
+ - [Usage](#usage)
44
+ - [Warning](#warning)
42
45
 
43
46
  ## Installation
44
47
 
@@ -211,3 +214,22 @@ python -m authlib.cli db init
211
214
  ```bash
212
215
  pytest
213
216
  ```
217
+
218
+ ## API Token Override for Testing
219
+
220
+ For testing purposes, you can bypass the database and provide a static mapping of API tokens to usernames using the `api_tokens` argument to `AuthManager` or the `{PREFIX}API_TOKENS` environment variable.
221
+
222
+ ### Usage
223
+
224
+ - **Constructor argument:**
225
+ ```python
226
+ AuthManager(api_tokens={"token1": "user1", "token2": "user2"})
227
+ ```
228
+ - **Environment variable:**
229
+ Set `{PREFIX}API_TOKENS` to a comma-separated list of `token:username` pairs, e.g.:
230
+ ```
231
+ export MYAPP_API_TOKENS="token1:user1,token2:user2"
232
+ ```
233
+ Replace `MYAPP` with your environment prefix.
234
+
235
+ **Warning:** This method is intended only for testing and development. Do not use this approach in production environments.