changeset 5466:398d936e77fb

mod_http_oauth2: Add support for the OpenID 'login_hint' parameter This allows the client to suggest to the authorization screen which user is trying to login, so they don't have to fill that in twice if they already did so at the client.
author Kim Alvefur <zash@zash.se>
date Wed, 17 May 2023 18:49:22 +0200
parents 66e13e79928b
children 1c78a97a1091
files mod_http_oauth2/html/login.html mod_http_oauth2/mod_http_oauth2.lua
diffstat 2 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_oauth2/html/login.html	Wed May 17 17:56:56 2023 +0200
+++ b/mod_http_oauth2/html/login.html	Wed May 17 18:49:22 2023 +0200
@@ -16,8 +16,8 @@
 		<p>{state.error}</p>
 	</div>}
 	<form method="post">
-		<input type="text" name="username" placeholder="Username" aria-label="Username" required autofocus><br/>
-		<input type="password" name="password" placeholder="Password" aria-label="Password" autocomplete="current-password" required><br/>
+		<input type="text" name="username" placeholder="Username" aria-label="Username" required {extra.no_username_hint&autofocus}{extra.username_hint& value="{extra.username_hint?}"}><br/>
+		<input type="password" name="password" placeholder="Password" aria-label="Password" autocomplete="current-password" required {extra.username_hint&autofocus}><br/>
 		<input type="submit" value="Sign in">
 	</form>
 	</fieldset>
--- a/mod_http_oauth2/mod_http_oauth2.lua	Wed May 17 17:56:56 2023 +0200
+++ b/mod_http_oauth2/mod_http_oauth2.lua	Wed May 17 18:49:22 2023 +0200
@@ -707,7 +707,12 @@
 	local auth_state = get_auth_state(request);
 	if not auth_state.user then
 		-- Render login page
-		return render_page(templates.login, { state = auth_state, client = client });
+		local extra = {};
+		if params.login_hint then
+			extra.username_hint = (jid.prepped_split(params.login_hint));
+			extra.no_username_hint = not extra.username_hint;
+		end
+		return render_page(templates.login, { state = auth_state; client = client; extra = extra });
 	elseif auth_state.consent == nil then
 		-- Render consent page
 		local scopes, roles = split_scopes(requested_scopes);