Skip to content

Commit 6a10e69

Browse files
authored
fix: use consistent underscored subject name for form param keys (#728)
Remove `slugify()` from the `as:` option and `get_params/2` in all form components. The `as:` option determines the key under which form params are nested, and `get_params/2` extracts them back out. These must match each other AND the ash_authentication plugs, which use `to_string()` without slugification. Previously some components slugified (producing `"admin-user"`) while others didn't (producing `"admin_user"`), and the plugs always expected the underscored form. This caused silent param lookup failures for multi-word subject names like `AdminUser`. Closes #726
1 parent 54b60e4 commit 6a10e69

10 files changed

Lines changed: 5 additions & 15 deletions

File tree

lib/ash_authentication_phoenix/components/confirm/form.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ defmodule AshAuthentication.Phoenix.Components.Confirm.Form do
161161
strategy.resource
162162
|> Info.authentication_subject_name!()
163163
|> to_string()
164-
|> slugify()
165164

166165
Map.get(params, param_key, %{})
167166
end

lib/ash_authentication_phoenix/components/magic_link.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ defmodule AshAuthentication.Phoenix.Components.MagicLink do
173173
strategy.resource
174174
|> Info.authentication_subject_name!()
175175
|> to_string()
176-
|> slugify()
177176

178177
Map.get(params, param_key, %{})
179178
end

lib/ash_authentication_phoenix/components/password/register_form.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ defmodule AshAuthentication.Phoenix.Components.Password.RegisterForm do
239239
strategy.resource
240240
|> Info.authentication_subject_name!()
241241
|> to_string()
242-
|> slugify()
243242

244243
Map.get(params, param_key, %{})
245244
end

lib/ash_authentication_phoenix/components/password/reset_form.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ defmodule AshAuthentication.Phoenix.Components.Password.ResetForm do
189189
strategy.resource
190190
|> Info.authentication_subject_name!()
191191
|> to_string()
192-
|> slugify()
193192

194193
Map.get(params, param_key, %{})
195194
end

lib/ash_authentication_phoenix/components/password/sign_in_form.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ defmodule AshAuthentication.Phoenix.Components.Password.SignInForm do
103103
strategy.resource
104104
|> Form.for_action(strategy.sign_in_action_name,
105105
domain: domain,
106-
as: subject_name |> to_string() |> slugify(),
106+
as: subject_name |> to_string(),
107107
id:
108108
"#{subject_name}-#{Strategy.name(strategy)}-#{strategy.sign_in_action_name}"
109109
|> slugify(),
@@ -250,7 +250,6 @@ defmodule AshAuthentication.Phoenix.Components.Password.SignInForm do
250250
strategy.resource
251251
|> Info.authentication_subject_name!()
252252
|> to_string()
253-
|> slugify()
254253

255254
Map.get(params, param_key, %{})
256255
end

lib/ash_authentication_phoenix/components/recovery_code/verify_form.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ defmodule AshAuthentication.Phoenix.Components.RecoveryCode.VerifyForm do
9797
resource
9898
|> Form.for_action(strategy.verify_action_name,
9999
domain: domain,
100-
as: subject_name |> to_string() |> slugify(),
100+
as: subject_name |> to_string(),
101101
id:
102102
"#{subject_name}-#{Strategy.name(strategy)}-verify-recovery-code"
103103
|> slugify(),
@@ -240,7 +240,6 @@ defmodule AshAuthentication.Phoenix.Components.RecoveryCode.VerifyForm do
240240
strategy.resource
241241
|> Info.authentication_subject_name!()
242242
|> to_string()
243-
|> slugify()
244243

245244
Map.get(params, param_key, %{})
246245
end

lib/ash_authentication_phoenix/components/reset/form.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ defmodule AshAuthentication.Phoenix.Components.Reset.Form do
202202
strategy.resource
203203
|> Info.authentication_subject_name!()
204204
|> to_string()
205-
|> slugify()
206205

207206
Map.get(params, param_key, %{})
208207
end

lib/ash_authentication_phoenix/components/totp/setup_form.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ if Code.ensure_loaded?(EQRCode) do
271271
strategy.resource
272272
|> Form.for_action(strategy.confirm_setup_action_name,
273273
domain: domain,
274-
as: subject_name |> to_string() |> slugify(),
274+
as: subject_name |> to_string(),
275275
id:
276276
"#{subject_name}-#{Strategy.name(strategy)}-#{strategy.confirm_setup_action_name}"
277277
|> slugify(),
@@ -342,7 +342,6 @@ if Code.ensure_loaded?(EQRCode) do
342342
strategy.resource
343343
|> Info.authentication_subject_name!()
344344
|> to_string()
345-
|> slugify()
346345

347346
Map.get(params, param_key, %{})
348347
end

lib/ash_authentication_phoenix/components/totp/sign_in_form.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule AshAuthentication.Phoenix.Components.Totp.SignInForm do
8888
strategy.resource
8989
|> Form.for_action(strategy.sign_in_action_name,
9090
domain: domain,
91-
as: subject_name |> to_string() |> slugify(),
91+
as: subject_name |> to_string(),
9292
id:
9393
"#{subject_name}-#{Strategy.name(strategy)}-#{strategy.sign_in_action_name}"
9494
|> slugify(),
@@ -189,7 +189,6 @@ defmodule AshAuthentication.Phoenix.Components.Totp.SignInForm do
189189
strategy.resource
190190
|> Info.authentication_subject_name!()
191191
|> to_string()
192-
|> slugify()
193192

194193
Map.get(params, param_key, %{})
195194
end

lib/ash_authentication_phoenix/components/totp/verify_2fa_form.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ defmodule AshAuthentication.Phoenix.Components.Totp.Verify2faForm do
120120
resource
121121
|> Form.for_action(strategy.verify_action_name,
122122
domain: domain,
123-
as: subject_name |> to_string() |> slugify(),
123+
as: subject_name |> to_string(),
124124
id:
125125
"#{subject_name}-#{Strategy.name(strategy)}-verify-2fa"
126126
|> slugify(),
@@ -276,7 +276,6 @@ defmodule AshAuthentication.Phoenix.Components.Totp.Verify2faForm do
276276
strategy.resource
277277
|> Info.authentication_subject_name!()
278278
|> to_string()
279-
|> slugify()
280279

281280
Map.get(params, param_key, %{})
282281
end

0 commit comments

Comments
 (0)