Skip to content

Custom Authentication Adapter

Andrea Tupini edited this page Sep 24, 2020 · 5 revisions

This uses the authentication provider registry to obtain a callable method that should accept a HttpRequestMessage and Subscription. This method is called just before the request message is sent. The method is free to change the request message instance as it sees fit (eg, by adding a custom header). Once this method ends, the modified request is sent to the external service.

Note that the Subscription instance passed to the custom authentication provider is a reference of the actual subscription managed by the EM. So avoid doing any changes to it unless you're absolutely sure what you're doing (any changes will be reflected back to the EM and may break stuff).

You can use EventDispatcher.customAuthProviderRegistry.AddAuthProvider(string name, Action<HttpRequestMessage, Subscription> action) to subscribe an action as provider, with specified name.

You can see the documentation for the CustomAuthAdapter here, and the documentation for the Entities.CustomAuthProviderRegistry class here.

Error handling on the provider side (the host)

If an error occurs while executing the provider then the host is responsible for catching this error and throwing an EventManager.BusinessLogic.Entities.Exceptions.CustomAuthFailureException. The EventManager Custom Auth Adapter will catch exceptions of this type and will simply log the error and queue the event to be resent. This also means that the custom auth provider method should be idempotent since it can be executed more than once for the same event.

If the custom auth provider method throws any other kind of exception then this will bubble up through the event manager until it reaches the top level of your application, and in most cases will be treated as an unhandled error (unless you implement some top-level error handling).

Clone this wiki locally