Skip to content

Commit

Permalink
Allow PublicKeyCredential JSON to have both id and rawId if equal
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Mar 15, 2021
1 parent ec9a900 commit d2b018c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Changes:

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

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


== Version 1.7.0 ==

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,34 @@ public class PublicKeyCredential<A extends AuthenticatorResponse, B extends Clie

@JsonCreator
private PublicKeyCredential(
@NonNull @JsonProperty("id") ByteArray id,
@JsonProperty("id") ByteArray id,
@JsonProperty("rawId") ByteArray rawId,
@NonNull @JsonProperty("response") A response,
@NonNull @JsonProperty("clientExtensionResults") B clientExtensionResults,
@NonNull @JsonProperty("type") PublicKeyCredentialType type
) {
this.id = id;
if (id == null && rawId == null) {
throw new NullPointerException("At least one of \"id\" and \"rawId\" must be non-null.");
}
if (id != null && rawId != null && !id.equals(rawId)) {
throw new IllegalArgumentException(String.format("\"id\" and \"rawId\" are not equal: %s != %s", id, rawId));
}

this.id = id == null ? rawId : id;
this.response = response;
this.clientExtensionResults = clientExtensionResults;
this.type = type;
}

private PublicKeyCredential(
ByteArray id,
@NonNull A response,
@NonNull B clientExtensionResults,
@NonNull PublicKeyCredentialType type
) {
this(id, null, response, clientExtensionResults, type);
}

public static <A extends AuthenticatorResponse, B extends ClientExtensionOutputs> PublicKeyCredentialBuilder<A, B>.MandatoryStages builder() {
return new PublicKeyCredentialBuilder<A, B>().start();
}
Expand Down

0 comments on commit d2b018c

Please sign in to comment.