Skip to content

Commit 9a5bf82

Browse files
committed
Add approve deny form
1 parent c2d60d3 commit 9a5bf82

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Accept or Deny</title>
5+
</head>
6+
<body>
7+
<h1>Please choose an action:</h1>
8+
<form method="post">
9+
{% csrf_token %}
10+
<button type="submit" name="action" value="accept">Accept</button>
11+
<button type="submit" name="action" value="deny">Deny</button>
12+
</form>
13+
</body>
14+
</html>

oauth2_provider/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
path("introspect/", views.IntrospectTokenView.as_view(), name="introspect"),
1414
path("device-authorization/", views.DeviceAuthorizationView.as_view(), name="device-authorization"),
1515
path("device/", views.device_user_code_view, name="device"),
16+
path("device-confirm/<str:device_code>", views.device_confirm_view, name="device-confirm"),
1617
]
1718

1819

oauth2_provider/views/device.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,24 @@ def device_user_code_view(request):
8080
return http.HttpResponsePermanentRedirect(
8181
reverse("oauth2_provider:device-confirm", kwargs={"device_code": device.device_code}), status=308
8282
)
83+
84+
85+
@login_required
86+
def device_confirm_view(request: http.HttpRequest, device_code: str):
87+
device: Device = get_device_model().objects.get(device_code=device_code)
88+
89+
if device.status in (device.AUTHORIZED, device.DENIED):
90+
return http.HttpResponse("Invalid")
91+
92+
action = request.POST.get("action")
93+
94+
if action == "accept":
95+
device.status = device.AUTHORIZED
96+
device.save(update_fields=["status"])
97+
return http.HttpResponse("approved")
98+
elif action == "deny":
99+
device.status = device.DENIED
100+
device.save(update_fields=["status"])
101+
return http.HttpResponse("deny")
102+
103+
return render(request, "oauth2_provider/device/accept_deny.html")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Accept or Deny</title>
5+
</head>
6+
<body>
7+
<h1>Please choose an action:</h1>
8+
<form method="post">
9+
{% csrf_token %}
10+
<button type="submit" name="action" value="accept">Accept</button>
11+
<button type="submit" name="action" value="deny">Deny</button>
12+
</form>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)