the37lab-authlib 0.1.1750840354__py3-none-any.whl → 0.1.1750840398__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/__init__.py +2 -2
- the37lab_authlib/auth.py +7 -24
- the37lab_authlib/decorators.py +1 -7
- {the37lab_authlib-0.1.1750840354.dist-info → the37lab_authlib-0.1.1750840398.dist-info}/METADATA +1 -1
- the37lab_authlib-0.1.1750840398.dist-info/RECORD +10 -0
- the37lab_authlib-0.1.1750840354.dist-info/RECORD +0 -10
- {the37lab_authlib-0.1.1750840354.dist-info → the37lab_authlib-0.1.1750840398.dist-info}/WHEEL +0 -0
- {the37lab_authlib-0.1.1750840354.dist-info → the37lab_authlib-0.1.1750840398.dist-info}/top_level.txt +0 -0
the37lab_authlib/__init__.py
CHANGED
the37lab_authlib/auth.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import inspect
|
|
2
|
-
from flask import Blueprint, request, jsonify, current_app, url_for, redirect
|
|
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')
|
the37lab_authlib/decorators.py
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
|
|
2
|
+
the37lab_authlib/auth.py,sha256=DKHWD-q67VSzddKGBRzkPxbrJPEBaNdeqMBsWgz4qHE,20852
|
|
3
|
+
the37lab_authlib/db.py,sha256=fTXxnfju0lmbFGPVbXpTMeDmJMeBgURVZTndyxyRyCc,2734
|
|
4
|
+
the37lab_authlib/decorators.py,sha256=AEQfix31fHUZvhEZd4Ud8Zh2KBGjV6O_braiPL-BU7w,1219
|
|
5
|
+
the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
|
|
6
|
+
the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
|
|
7
|
+
the37lab_authlib-0.1.1750840398.dist-info/METADATA,sha256=ibXPUKnoIxAvfF6rilvv6SHADZuT5YKAolb93utKKNg,5641
|
|
8
|
+
the37lab_authlib-0.1.1750840398.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
the37lab_authlib-0.1.1750840398.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
|
|
10
|
+
the37lab_authlib-0.1.1750840398.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
the37lab_authlib/__init__.py,sha256=YV1C1iaIs-8cD5dFe-VEC6dRhrT6mglgTdcveT6AMCQ,168
|
|
2
|
-
the37lab_authlib/auth.py,sha256=dkmRfkJ03W8FsLO1OcT_erG0DzP7kMlpPdrw_jts0IE,21372
|
|
3
|
-
the37lab_authlib/db.py,sha256=fTXxnfju0lmbFGPVbXpTMeDmJMeBgURVZTndyxyRyCc,2734
|
|
4
|
-
the37lab_authlib/decorators.py,sha256=oBO3fbRo7H0rcXeUq6M8yK-5mgHKfaJEDG6XdNsxQPI,1351
|
|
5
|
-
the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
|
|
6
|
-
the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
|
|
7
|
-
the37lab_authlib-0.1.1750840354.dist-info/METADATA,sha256=01Z5Jknra_QYDGgu-_qNC9Rqz0sCafF2TdzI7LaVmgU,5641
|
|
8
|
-
the37lab_authlib-0.1.1750840354.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
the37lab_authlib-0.1.1750840354.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
|
|
10
|
-
the37lab_authlib-0.1.1750840354.dist-info/RECORD,,
|
{the37lab_authlib-0.1.1750840354.dist-info → the37lab_authlib-0.1.1750840398.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|