Interface Dispatcher

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Dispatcher
An object that is responsible for sending tokens that the client can redeem. Examples of dispatchers are:
  • Firebase Cloud Messaging dispatcher: sends the token to a mobile client in a push notification.
  • QR code dispatcher: includes the token in a QR code that a mobile device can scan to obtain the token.

Dispatchers are used in the out-of-band use cases supported by nevisFIDO. Dispatchers are a pluggable mechanism to send tokens to arbitrary dispatch targets and thus initiate a FIDO UAF flow out-of-band.

This API offers some convenience methods to dispatch contents that can be consumed by the Nevis Mobile Authentication SDK. Here we present a basic layout of a dispatcher implementation:

     // ConfigurationKey is used to provide the type of the dispatcher as referred in the
     // configuration.
     @ConfigurationKey("message-in-a-bottle")
     public class MessageInABottleDispatcher implements Dispatcher, Configurable {
         private URI redeemUrl;

         // Here we assume that the URL required to redeem the token by the client is stored
         // in the configuration and that the configuration is:
         // - type: message-in-a-bottle
         //   redeem-url: https://siven/redeem
         //
         // Because we want to read the configuration contents, this dispatcher implements Configurable.
         // Note that you can use the configuration or any other way to obtain the redeem URL
         // that is required to build the out-of-band payload
         @Override
         public void configure(Map<String, Object> configuration) throws InvalidConfigurationException {
             try {
                 this.redeemUrl = new URI((String) configuration. get("redeem-url"));
             } catch (URISyntaxException e) {
                 throw new InvalidConfigurationException("Invalid configuration: " + configuration, e);
             }
         }

         @Override
         public DispatcherResponse dispatch(DispatchContext dispatchContext) throws DispatchException {
             String outOfBandPayload = dispatchContext.mobileSdkOutOfBandPayloadBuilder()
                 .redeemUrl(redeemUrl)
                 .build();
             // TODO: dispatch the out-of-band payload.
             // Here the dispatcher must do whatever it is needed so that the out-of-band
             // payload reaches the client where the Nevis Mobile SDK is running. A push
             // notification dispatcher would generate a push notification with
             // the outOfBandPayload, this dispatcher will put it in a bottle and throw it
             // in the sea. If there is an error during the dispatching, the code must
             // throw a DispatchException.

             return dispatchContext.mobileSdkDispatcherResponseBuilder()
                 .redeemUrl(redeemUrl)
                 // This is the dispatch information that will be exposed by the status service
                 .statusResponse("sent")
                 // This is the information that will be returned to the HTTP client that
                 // started this dispatch operation
                 .httpResponse("The bottle has been sent.")
                 .build();
         }
     }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    dispatch(DispatchContext dispatchContext)
    Dispatches a message to the dispatcher target.