mod_http_oauth2: Show errors on device flow user code entry page
If the user enters the code incorrectly, having to click back to try
again is no fun. Instead, show the error and the code entry form again.
--- a/mod_http_oauth2/html/device.html Wed Jul 19 12:58:04 2023 +0200
+++ b/mod_http_oauth2/html/device.html Wed Jul 19 13:05:47 2023 +0200
@@ -11,6 +11,9 @@
<h1>{site_name}</h1>
<fieldset>
<legend>Device Authorization</legend>
+ {error&<div class="error">
+ <p>{error.text}</p>
+ </div>}
{client&
<p>Authorization completed. You can go back to
<em>{client.client_name}</em>.</p>}
--- a/mod_http_oauth2/mod_http_oauth2.lua Wed Jul 19 12:58:04 2023 +0200
+++ b/mod_http_oauth2/mod_http_oauth2.lua Wed Jul 19 13:05:47 2023 +0200
@@ -1011,7 +1011,10 @@
local device_info = codes:get("user_code:" .. params.user_code);
if not device_info or code_expired(device_info) or not codes:set("user_code:" .. params.user_code, nil) then
- return render_error(oauth_error("expired_token", "Incorrect or expired code"));
+ return render_page(templates.device, {
+ client = false;
+ error = oauth_error("expired_token", "Incorrect or expired code");
+ });
end
return {