Commit 94d4607
committed
fix(serializer): attributes with hashes as values ending up without camelCase keys in Rails
In Rails, doing
```
WebAuthn::Credential.options_for_create(user: { name: 'john', id: WebAuthn.generate_user_id }, authenticator_selection: { user_verification: "required" }).as_json
```
results in:
```
{:challenge=>"QVFtcdn_znYUWzAzmBSGpOPWweTs1tBmqPQENeGjUvA",
:timeout=>120000,
:extensions=>{},
:rp=>{:name=>"WebAuthn Rails Demo App"},
:user=>{:name=>"john", :id=>"8kzxeLCJ13lE5g7T7pE0TxCRxy_4Mcpp1lWS6geXJAiz7rPXHOWSJy_Ou33GP7lCvn_u5uIhDZzOez_cWoMGcA", :displayName=>"john"},
:pubKeyCredParams=>[{"type"=>"public-key", "alg"=>-7}, {"type"=>"public-key", "alg"=>-37}, {"type"=>"public-key", "alg"=>-257}],
:authenticatorSelection=>{"user_verification"=>"required"}}
```
(Notice the `user_verification` key under `authenticatorSelection`
without being camelCased)
This causes errors with some authenticators – particularly with
1Password.
The issue is that for the attributes whose value is a hash – as in
Rails, hash objects respond to `as_json` – are not going through the
part of the condition that calls camelCases its keys.
To fix this, this commit attempts to go back at the initial approach -
before 0aab124 – that first converts the object into a hash and then
camel cases its keys, even though more iterations are performed on the
object.1 parent 00b30c5 commit 94d4607
1 file changed
Lines changed: 8 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
0 commit comments