shopcloud-django-authenticator 1.0.2__py3.11.egg → 1.2.0__py3.11.egg
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.
- EGG-INFO/PKG-INFO +1 -1
- authenticator/__pycache__/__init__.cpython-311.pyc +0 -0
- authenticator/__pycache__/admin.cpython-311.pyc +0 -0
- authenticator/__pycache__/apps.cpython-311.pyc +0 -0
- authenticator/__pycache__/models.cpython-311.pyc +0 -0
- authenticator/__pycache__/tests.cpython-311.pyc +0 -0
- authenticator/__pycache__/urls.cpython-311.pyc +0 -0
- authenticator/__pycache__/views.cpython-311.pyc +0 -0
- authenticator/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
- authenticator/urls.py +1 -0
- authenticator/views.py +48 -13
- tests/__pycache__/__init__.cpython-311.pyc +0 -0
- tests/__pycache__/urls.cpython-311.pyc +0 -0
EGG-INFO/PKG-INFO
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
authenticator/urls.py
CHANGED
|
@@ -8,6 +8,7 @@ router = routers.SimpleRouter()
|
|
|
8
8
|
|
|
9
9
|
urlpatterns = [
|
|
10
10
|
path('login', views.login_view, name='authenticator-login'),
|
|
11
|
+
path('login-credential-rotation', views.login_credential_rotation, name='authenticator-login-credential-rotation'),
|
|
11
12
|
]
|
|
12
13
|
urlpatterns += router.urls
|
|
13
14
|
urlpatterns = format_suffix_patterns(urlpatterns)
|
authenticator/views.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
1
3
|
import jwt
|
|
2
4
|
from django.conf import settings
|
|
3
5
|
from django.contrib.auth import login
|
|
4
6
|
from django.contrib.auth.models import User
|
|
5
|
-
from django.http import HttpResponse
|
|
7
|
+
from django.http import HttpResponse, JsonResponse
|
|
6
8
|
from django.shortcuts import redirect
|
|
7
9
|
|
|
8
10
|
|
|
@@ -10,13 +12,13 @@ class HttpResponseUnauthorized(HttpResponse):
|
|
|
10
12
|
status_code = 401
|
|
11
13
|
|
|
12
14
|
|
|
13
|
-
def
|
|
15
|
+
def _encode_jwt(request) -> Optional[dict]:
|
|
14
16
|
token = request.GET.get('token')
|
|
15
17
|
if token is None:
|
|
16
|
-
return
|
|
18
|
+
return None
|
|
17
19
|
|
|
18
20
|
if settings.AUTHENTICATOR_KEY is None:
|
|
19
|
-
return
|
|
21
|
+
return None
|
|
20
22
|
|
|
21
23
|
data = jwt.decode(
|
|
22
24
|
token,
|
|
@@ -30,7 +32,19 @@ def login_view(request):
|
|
|
30
32
|
]
|
|
31
33
|
}
|
|
32
34
|
)
|
|
33
|
-
if data.get('iss')
|
|
35
|
+
if data.get('iss') not in ['shopcloud-secrethub', 'shopcloud-tower']:
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
return data
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def login_view(request):
|
|
42
|
+
try:
|
|
43
|
+
data = _encode_jwt(request)
|
|
44
|
+
except Exception:
|
|
45
|
+
return HttpResponseUnauthorized()
|
|
46
|
+
|
|
47
|
+
if data is None:
|
|
34
48
|
return HttpResponseUnauthorized()
|
|
35
49
|
|
|
36
50
|
user = User.objects.filter(username=data.get('username')).first()
|
|
@@ -40,15 +54,36 @@ def login_view(request):
|
|
|
40
54
|
username=data.get('username'),
|
|
41
55
|
password=password,
|
|
42
56
|
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
else
|
|
47
|
-
|
|
48
|
-
user.is_staff = True
|
|
49
|
-
user.is_superuser = True if "admin" in data.get('scopes', []) else False
|
|
50
|
-
user.save()
|
|
57
|
+
|
|
58
|
+
user.set_password(password)
|
|
59
|
+
user.is_staff = True
|
|
60
|
+
user.is_superuser = True if "admin" in data.get('scopes', []) else False
|
|
61
|
+
user.save()
|
|
51
62
|
|
|
52
63
|
login(request, user)
|
|
53
64
|
|
|
54
65
|
return redirect('/', permanent=False)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def login_credential_rotation(request):
|
|
69
|
+
try:
|
|
70
|
+
data = _encode_jwt(request)
|
|
71
|
+
except Exception:
|
|
72
|
+
return HttpResponseUnauthorized()
|
|
73
|
+
|
|
74
|
+
if data is None:
|
|
75
|
+
return HttpResponseUnauthorized()
|
|
76
|
+
|
|
77
|
+
user = User.objects.filter(username=data.get('username')).first()
|
|
78
|
+
if user is None:
|
|
79
|
+
return JsonResponse({
|
|
80
|
+
'status': 'not-found',
|
|
81
|
+
}, status=200)
|
|
82
|
+
|
|
83
|
+
password = User.objects.make_random_password()
|
|
84
|
+
user.set_password(password)
|
|
85
|
+
user.save()
|
|
86
|
+
|
|
87
|
+
return JsonResponse({
|
|
88
|
+
'status': 'ok',
|
|
89
|
+
}, status=201)
|
|
Binary file
|
|
Binary file
|