Class WebAuthnSecurity

java.lang.Object
io.quarkus.security.webauthn.WebAuthnSecurity

@ApplicationScoped public class WebAuthnSecurity extends Object
Utility class that allows users to manually login or register users using WebAuthn
  • Field Details

  • Constructor Details

  • Method Details

    • getRegisterChallenge

      public io.smallrye.mutiny.Uni<com.webauthn4j.data.PublicKeyCredentialCreationOptions> getRegisterChallenge(String username, String displayName, io.vertx.ext.web.RoutingContext ctx)
      Obtains a registration challenge for the given required username and displayName. This will also create and save a challenge in a session cookie.
      Parameters:
      username - the username for the registration
      displayName - the displayName for the registration
      ctx - the Vert.x context
      Returns:
      the registration challenge.
    • getLoginChallenge

      public io.smallrye.mutiny.Uni<com.webauthn4j.data.PublicKeyCredentialRequestOptions> getLoginChallenge(String username, io.vertx.ext.web.RoutingContext ctx)
      Obtains a login challenge for the given optional username. This will also create and save a challenge in a session cookie.
      Parameters:
      username - the optional username for the login
      ctx - the Vert.x context
      Returns:
      the login challenge.
    • register

      public io.smallrye.mutiny.Uni<WebAuthnCredentialRecord> register(String username, WebAuthnRegisterResponse response, io.vertx.ext.web.RoutingContext ctx)
      Registers a new WebAuthn credentials. This will check it, clear the challenge cookie and return it in case of success, but not invoke WebAuthnUserProvider.store(WebAuthnCredentialRecord), you have to do it manually in case of success. This will also not set a login cookie, you have to do it manually using rememberUser(String, RoutingContext) or using any other way.
      Parameters:
      response - the Webauthn registration info
      ctx - the current request
      the - username to register credentials for
      Returns:
      the newly created credentials
    • register

      public io.smallrye.mutiny.Uni<WebAuthnCredentialRecord> register(String username, io.vertx.core.json.JsonObject response, io.vertx.ext.web.RoutingContext ctx)
      Registers a new WebAuthn credentials. This will check it, clear the challenge cookie and return it in case of success, but not invoke WebAuthnUserProvider.store(WebAuthnCredentialRecord), you have to do it manually in case of success. This will also not set a login cookie, you have to do it manually using rememberUser(String, RoutingContext) or using any other way.
      Parameters:
      response - the Webauthn registration info
      ctx - the current request
      the - username to register credentials for
      Returns:
      the newly created credentials
    • login

      public io.smallrye.mutiny.Uni<WebAuthnCredentialRecord> login(WebAuthnLoginResponse response, io.vertx.ext.web.RoutingContext ctx)
      Logs an existing WebAuthn user in. This will check it, clear the challenge cookie and return the updated credentials in case of success, but not invoke WebAuthnUserProvider.update(String, long), you have to do it manually in case of success. This will also not set a login cookie, you have to do it manually using rememberUser(String, RoutingContext) or using any other way.
      Parameters:
      response - the Webauthn login info
      ctx - the current request
      Returns:
      the updated credentials
    • login

      public io.smallrye.mutiny.Uni<WebAuthnCredentialRecord> login(io.vertx.core.json.JsonObject response, io.vertx.ext.web.RoutingContext ctx)
      Logs an existing WebAuthn user in. This will check it, clear the challenge cookie and return the updated credentials in case of success, but not invoke WebAuthnUserProvider.update(String, long), you have to do it manually in case of success. This will also not set a login cookie, you have to do it manually using rememberUser(String, RoutingContext) or using any other way.
      Parameters:
      response - the Webauthn login info
      ctx - the current request
      Returns:
      the updated credentials
    • removeCookie

      static void removeCookie(io.vertx.ext.web.RoutingContext ctx, String name)
    • getWebAuthn4J

      public com.webauthn4j.async.WebAuthnAsyncManager getWebAuthn4J()
      Returns the underlying WebAuthn4J authenticator
      Returns:
      the underlying WebAuthn4J authenticator
    • rememberUser

      public void rememberUser(String userID, io.vertx.ext.web.RoutingContext ctx)
      Adds a login cookie to the current request for the given user ID
      Parameters:
      userID - the user ID to use as Principal
      ctx - the current request, in order to add a cookie
    • logout

      public void logout(io.vertx.ext.web.RoutingContext ctx)
      Clears the login cookie on the current request
      Parameters:
      ctx - the current request, in order to clear the login cookie
    • containsRequiredString

      static boolean containsRequiredString(io.vertx.core.json.JsonObject json, String key)
    • toJsonString

      public String toJsonString(com.webauthn4j.data.PublicKeyCredentialCreationOptions challenge)
    • toJsonString

      public String toJsonString(com.webauthn4j.data.PublicKeyCredentialRequestOptions challenge)
    • getAllowedOrigins

      public List<String> getAllowedOrigins(io.vertx.ext.web.RoutingContext ctx)
      Returns the list of allowed origins, or defaults to the current request's origin if unconfigured.
    • storage