the37lab-authlib 0.1.1750840354__tar.gz → 0.1.1750840398__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 (16) hide show
  1. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/PKG-INFO +1 -1
  2. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/pyproject.toml +1 -1
  3. the37lab_authlib-0.1.1750840398/src/the37lab_authlib/__init__.py +5 -0
  4. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib/auth.py +7 -24
  5. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib/decorators.py +1 -7
  6. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib.egg-info/PKG-INFO +1 -1
  7. the37lab_authlib-0.1.1750840354/src/the37lab_authlib/__init__.py +0 -5
  8. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/README.md +0 -0
  9. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/setup.cfg +0 -0
  10. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib/db.py +0 -0
  11. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib/exceptions.py +0 -0
  12. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib/models.py +0 -0
  13. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib.egg-info/SOURCES.txt +0 -0
  14. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib.egg-info/dependency_links.txt +0 -0
  15. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/src/the37lab_authlib.egg-info/requires.txt +0 -0
  16. {the37lab_authlib-0.1.1750840354 → the37lab_authlib-0.1.1750840398}/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.1750840354
3
+ Version: 0.1.1750840398
4
4
  Summary: Python SDK for the Authlib
5
5
  Author-email: the37lab <info@the37lab.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "the37lab_authlib"
7
- version = "0.1.1750840354"
7
+ version = "0.1.1750840398"
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"]
@@ -0,0 +1,5 @@
1
+ from .auth import AuthManager
2
+ from .decorators import require_auth
3
+
4
+ __version__ = "0.1.0"
5
+ __all__ = ["AuthManager", "require_auth"]
@@ -1,11 +1,10 @@
1
1
  import inspect
2
- from flask import Blueprint, request, jsonify, current_app, url_for, redirect, g
2
+ from flask import Blueprint, request, jsonify, current_app, url_for, redirect
3
3
  import jwt
4
4
  from datetime import datetime, timedelta
5
5
  from .db import Database
6
6
  from .models import User, Role, ApiToken
7
7
  from .exceptions import AuthError
8
- from .decorators import public_endpoint
9
8
  import uuid
10
9
  import requests
11
10
  import bcrypt
@@ -129,24 +128,16 @@ class AuthManager:
129
128
  def init_app(self, app):
130
129
  app.auth_manager = self
131
130
  app.register_blueprint(self.create_blueprint())
131
+ @app.errorhandler(AuthError)
132
+ def handle_auth_error(e):
133
+ response = jsonify(e.to_dict())
134
+ response.status_code = e.status_code
135
+ return response
132
136
 
133
137
  def create_blueprint(self):
134
138
  bp = Blueprint('auth', __name__, url_prefix='/api/v1/users')
135
139
 
136
- @bp.before_request
137
- def load_user():
138
- view = current_app.view_functions.get(request.endpoint)
139
- if getattr(view, '_auth_public', False):
140
- return
141
- try:
142
- g.current_user = self._authenticate_request()
143
- except AuthError as e:
144
- response = jsonify(e.to_dict())
145
- response.status_code = e.status_code
146
- return response
147
-
148
140
  @bp.route('/login', methods=['POST'])
149
- @public_endpoint
150
141
  @handle_auth_errors
151
142
  def login():
152
143
  data = request.get_json()
@@ -182,7 +173,6 @@ class AuthManager:
182
173
  })
183
174
 
184
175
  @bp.route('/login/oauth', methods=['POST'])
185
- @public_endpoint
186
176
  @handle_auth_errors
187
177
  def oauth_login():
188
178
  provider = request.json.get('provider')
@@ -195,7 +185,6 @@ class AuthManager:
195
185
  })
196
186
 
197
187
  @bp.route('/login/oauth2callback')
198
- @public_endpoint
199
188
  @handle_auth_errors
200
189
  def oauth_callback():
201
190
  code = request.args.get('code')
@@ -244,7 +233,6 @@ class AuthManager:
244
233
  })
245
234
 
246
235
  @bp.route('/token-refresh', methods=['POST'])
247
- @public_endpoint
248
236
  @handle_auth_errors
249
237
  def refresh_token():
250
238
  refresh_token = request.json.get('refresh_token')
@@ -335,7 +323,6 @@ class AuthManager:
335
323
  return jsonify({'deleted': True})
336
324
 
337
325
  @bp.route('/register', methods=['POST'])
338
- @public_endpoint
339
326
  @handle_auth_errors
340
327
  def register():
341
328
  data = request.get_json()
@@ -375,7 +362,6 @@ class AuthManager:
375
362
  return jsonify({'id': user.id}), 201
376
363
 
377
364
  @bp.route('/roles', methods=['GET'])
378
- @public_endpoint
379
365
  @handle_auth_errors
380
366
  def get_roles():
381
367
  with self.db.get_cursor() as cur:
@@ -416,8 +402,6 @@ class AuthManager:
416
402
  raise AuthError(str(e), 500)
417
403
 
418
404
  def get_current_user(self):
419
- if hasattr(g, 'current_user'):
420
- return g.current_user
421
405
  return self._authenticate_request()
422
406
 
423
407
  def get_user_api_tokens(self, user_id):
@@ -472,7 +456,6 @@ class AuthManager:
472
456
  return f'https://accounts.google.com/o/oauth2/v2/auth?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope={scope}&state={state}'
473
457
  raise AuthError('Invalid OAuth provider')
474
458
 
475
-
476
459
  def _get_oauth_user_info(self, provider, code):
477
460
  if provider == 'google':
478
461
  client_id = self.oauth_config['google']['client_id']
@@ -534,4 +517,4 @@ class AuthManager:
534
517
  user['real_name'] = userinfo.get('name', userinfo['email'])
535
518
 
536
519
  return user
537
- raise AuthError('Invalid OAuth provider')
520
+ raise AuthError('Invalid OAuth provider')
@@ -2,12 +2,6 @@ from functools import wraps
2
2
  from flask import request, current_app, jsonify
3
3
  from .exceptions import AuthError
4
4
 
5
-
6
- def public_endpoint(f):
7
- """Mark an endpoint as public (no authentication required)."""
8
- f._auth_public = True
9
- return f
10
-
11
5
  def require_auth(roles=None):
12
6
  def decorator(f):
13
7
  @wraps(f)
@@ -34,4 +28,4 @@ def require_auth(roles=None):
34
28
  response.status_code = e.status_code
35
29
  return response
36
30
  return decorated
37
- return decorator
31
+ return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: the37lab_authlib
3
- Version: 0.1.1750840354
3
+ Version: 0.1.1750840398
4
4
  Summary: Python SDK for the Authlib
5
5
  Author-email: the37lab <info@the37lab.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,5 +0,0 @@
1
- from .auth import AuthManager
2
- from .decorators import require_auth, public_endpoint
3
-
4
- __version__ = "0.1.0"
5
- __all__ = ["AuthManager", "require_auth", "public_endpoint"]