Skip to content

Commit d2b018c

Browse files
committed
Allow PublicKeyCredential JSON to have both id and rawId if equal
1 parent ec9a900 commit d2b018c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Changes:
1111

1212
Note that `webauthn-server-attestation` still depends on BouncyCastle.
1313

14+
* Jackson deserializer for `PublicKeyCredential` now allows a `rawId` property
15+
to be present if `id` is not present, or if `rawId` equals `id`.
16+
1417

1518
== Version 1.7.0 ==
1619

webauthn-server-core/src/main/java/com/yubico/webauthn/data/PublicKeyCredential.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,34 @@ public class PublicKeyCredential<A extends AuthenticatorResponse, B extends Clie
8484

8585
@JsonCreator
8686
private PublicKeyCredential(
87-
@NonNull @JsonProperty("id") ByteArray id,
87+
@JsonProperty("id") ByteArray id,
88+
@JsonProperty("rawId") ByteArray rawId,
8889
@NonNull @JsonProperty("response") A response,
8990
@NonNull @JsonProperty("clientExtensionResults") B clientExtensionResults,
9091
@NonNull @JsonProperty("type") PublicKeyCredentialType type
9192
) {
92-
this.id = id;
93+
if (id == null && rawId == null) {
94+
throw new NullPointerException("At least one of \"id\" and \"rawId\" must be non-null.");
95+
}
96+
if (id != null && rawId != null && !id.equals(rawId)) {
97+
throw new IllegalArgumentException(String.format("\"id\" and \"rawId\" are not equal: %s != %s", id, rawId));
98+
}
99+
100+
this.id = id == null ? rawId : id;
93101
this.response = response;
94102
this.clientExtensionResults = clientExtensionResults;
95103
this.type = type;
96104
}
97105

106+
private PublicKeyCredential(
107+
ByteArray id,
108+
@NonNull A response,
109+
@NonNull B clientExtensionResults,
110+
@NonNull PublicKeyCredentialType type
111+
) {
112+
this(id, null, response, clientExtensionResults, type);
113+
}
114+
98115
public static <A extends AuthenticatorResponse, B extends ClientExtensionOutputs> PublicKeyCredentialBuilder<A, B>.MandatoryStages builder() {
99116
return new PublicKeyCredentialBuilder<A, B>().start();
100117
}

0 commit comments

Comments
 (0)