the37lab-authlib 0.1.1750836881__py3-none-any.whl → 0.1.1750837371__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.

Potentially problematic release.


This version of the37lab-authlib might be problematic. Click here for more details.

the37lab_authlib/auth.py CHANGED
@@ -22,6 +22,15 @@ class AuthManager:
22
22
  self.jwt_secret = jwt_secret
23
23
  logger.debug(f"Initializing AuthManager with JWT secret: {jwt_secret[:5]}..." if jwt_secret else "No JWT secret provided")
24
24
  self.oauth_config = oauth_config or {}
25
+ self.public_endpoints = {
26
+ 'auth.login',
27
+ 'auth.oauth_login',
28
+ 'auth.oauth_callback',
29
+ 'auth.refresh_token',
30
+ 'auth.register',
31
+ 'auth.get_roles'
32
+ }
33
+ self.bp = None
25
34
 
26
35
  if app:
27
36
  self.init_app(app)
@@ -113,6 +122,17 @@ class AuthManager:
113
122
 
114
123
  return f(*args, **kwargs)
115
124
  return decorated
125
+
126
+ def add_public_endpoint(self, endpoint):
127
+ """Mark an endpoint as public so it bypasses authentication."""
128
+ self.public_endpoints.add(endpoint)
129
+
130
+ def public_endpoint(self, f):
131
+ """Decorator to mark a view function as public."""
132
+ if self.bp:
133
+ endpoint = f"{self.bp.name}.{f.__name__}"
134
+ self.add_public_endpoint(endpoint)
135
+ return f
116
136
 
117
137
  def init_app(self, app):
118
138
  app.auth_manager = self
@@ -120,15 +140,8 @@ class AuthManager:
120
140
 
121
141
  def create_blueprint(self):
122
142
  bp = Blueprint('auth', __name__, url_prefix='/api/v1/users')
123
-
124
- public_endpoints = {
125
- 'auth.login',
126
- 'auth.oauth_login',
127
- 'auth.oauth_callback',
128
- 'auth.refresh_token',
129
- 'auth.register',
130
- 'auth.get_roles'
131
- }
143
+ self.bp = bp
144
+ bp.public_endpoint = self.public_endpoint
132
145
 
133
146
  @bp.errorhandler(AuthError)
134
147
  def handle_auth_error(err):
@@ -138,7 +151,7 @@ class AuthManager:
138
151
 
139
152
  @bp.before_request
140
153
  def load_user():
141
- if request.endpoint not in public_endpoints:
154
+ if request.endpoint not in self.public_endpoints:
142
155
  g.requesting_user = self._authenticate_request()
143
156
 
144
157
  @bp.route('/login', methods=['POST'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: the37lab_authlib
3
- Version: 0.1.1750836881
3
+ Version: 0.1.1750837371
4
4
  Summary: Python SDK for the Authlib
5
5
  Author-email: the37lab <info@the37lab.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -70,13 +70,20 @@ auth = AuthManager(
70
70
  @auth.require_auth(roles=["admin"])
71
71
  def protected_route():
72
72
  return "Protected content"
73
+
74
+ @app.route("/public")
75
+ @auth.public_endpoint
76
+ def custom_public_route():
77
+ return "Public content"
73
78
  ```
74
79
 
75
80
  `AuthManager`'s blueprint now registers a global error handler for
76
81
  `AuthError` and authenticates requests for all of its routes by default.
77
82
  Authenticated users are made available as `flask.g.requesting_user`.
78
83
  Only the login, OAuth, token refresh, registration and role listing
79
- endpoints are exempt from this check.
84
+ endpoints are exempt from this check. Additional routes can be marked as
85
+ public using the `@auth.public_endpoint` decorator or
86
+ `auth.add_public_endpoint("auth.some_endpoint")`.
80
87
 
81
88
  ## Configuration
82
89
 
@@ -1,10 +1,10 @@
1
1
  the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
2
- the37lab_authlib/auth.py,sha256=tBs-THT_sJeolT9hxwOmtCcsHCMfVEQXtYdVJOCRdAs,20338
2
+ the37lab_authlib/auth.py,sha256=qj3b5PBT2egtygQAAPBiHFcWEgfD-9cIOlMwP5_HJ3M,20835
3
3
  the37lab_authlib/db.py,sha256=fTXxnfju0lmbFGPVbXpTMeDmJMeBgURVZTndyxyRyCc,2734
4
4
  the37lab_authlib/decorators.py,sha256=AEQfix31fHUZvhEZd4Ud8Zh2KBGjV6O_braiPL-BU7w,1219
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.1750836881.dist-info/METADATA,sha256=Jdhr9dU1rR4pDX9m5VJooujmEOpAB0zAxCkmXKf0N_M,6113
8
- the37lab_authlib-0.1.1750836881.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- the37lab_authlib-0.1.1750836881.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
- the37lab_authlib-0.1.1750836881.dist-info/RECORD,,
7
+ the37lab_authlib-0.1.1750837371.dist-info/METADATA,sha256=nAsElJNxxbQgDfwvVe0Ia4_22MJ3i0VOyW8ZJk3vmO0,6352
8
+ the37lab_authlib-0.1.1750837371.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ the37lab_authlib-0.1.1750837371.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
+ the37lab_authlib-0.1.1750837371.dist-info/RECORD,,