Class AssertionRequest

java.lang.Object
com.yubico.webauthn.AssertionRequest

public final class AssertionRequest extends Object
A combination of a PublicKeyCredentialRequestOptions and, optionally, a username or user handle.
  • Method Details

    • getUsername

      public Optional<String> getUsername()
      The username of the user to authenticate, if the user has already been identified.

      This is mutually exclusive with getUserHandle(); if this is present, then getUserHandle() will be empty.

      If both this and getUserHandle() are empty, this indicates that this is a request for an assertion by a client-side-discoverable credential (passkey). Identification of the user is therefore deferred until the response is received.

      See Also:
    • getUserHandle

      public Optional<ByteArray> getUserHandle()
      The user handle of the user to authenticate, if the user has already been identified.

      This is mutually exclusive with getUsername(); if this is present, then getUsername() will be empty.

      If both this and getUsername() are empty, this indicates that this is a request for an assertion by a client-side-discoverable credential (passkey). Identification of the user is therefore deferred until the response is received.

      See Also:
    • toCredentialsGetJson

      public String toCredentialsGetJson() throws com.fasterxml.jackson.core.JsonProcessingException
      Serialize this AssertionRequest value to JSON suitable for sending to the client.

      This is an alias of getPublicKeyCredentialRequestOptions().toCredentialsGetJson() .

      Any ByteArray values in this data structure will be Base64Url encoded. Those values MUST be decoded into BufferSource values (such as Uint8Array) on the client side before calling navigator.credentials.get() .

      After decoding binary values, the resulting JavaScript object is suitable for passing as an argument to navigator.credentials.get().

      Returns:
      a JSON value suitable for sending to the client and passing as an argument to navigator.credentials.get(), after decoding binary options from Base64Url strings.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if JSON serialization fails.
    • toJson

      public String toJson() throws com.fasterxml.jackson.core.JsonProcessingException
      Encode this AssertionRequest to JSON. The inverse of fromJson(String).

      This method is suitable for encoding the AssertionRequest for temporary storage so that it can later be passed as an argument to RelyingParty.finishAssertion(FinishAssertionOptions). The fromJson(String) factory function is guaranteed to restore an identical AssertionRequest instance.

      Note that encoding might not be needed if you can simply keep the AssertionRequest instance in server memory.

      Returns:
      this AssertionRequest encoded to JSON.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • fromJson

      public static AssertionRequest fromJson(String json) throws com.fasterxml.jackson.core.JsonProcessingException
      Decode an AssertionRequest from JSON. The inverse of toJson().

      If the JSON was generated by the toJson() method, then fromJson(String) in the same library version guarantees to restore an identical AssertionRequest instance. This is not guaranteed between different library versions.

      Returns:
      a AssertionRequest decoded from the input JSON.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • builder

    • toBuilder

    • getPublicKeyCredentialRequestOptions

      @NonNull public @NonNull PublicKeyCredentialRequestOptions getPublicKeyCredentialRequestOptions()
      An object that can be serialized to JSON and passed as the publicKey argument to navigator.credentials.get().
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object