Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PublicKeyCredential::Options#.as_json not camelCase'ing keys of attributes with hash or arrays as values #445

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

santiagorodriguez96
Copy link
Contributor

Attempts to fix #444.

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.

…amelCase 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.
@brauliomartinezlm brauliomartinezlm merged commit c385f25 into master Nov 14, 2024
11 checks passed
@brauliomartinezlm brauliomartinezlm deleted the sr--fix-serializer branch November 14, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PublicKeyCredential::Options#.as_json not camelCase'ing keys of attributes with hash or arrays as values
2 participants