I have added all available middleware in OWIN Pipeline using Startup class to authenticate user in my project. It is working fine. But how can I add middleware to OWIN Pipeline after Startup at runtime. So that Admin can enter the details of new Authentication Server using UI and register new authentication server on demand without disturbing running application.
Actually, standard owin pipeline implementation is not designed to be modified during runtime. It has two lifetime phase: init (pipeline creation) and running (serving requests). The right and clear approach for your problem is to use middlewares which are support config modification at runtime.
In your case: If you use Kentor.AuthServices lib for authentication, then this support comes out of the box. You only need to register one middleware instance at startup, and when you modifiy (add or remove IdentityProviders) the KentorAuthServicesOptions instance that you provided originally, the changes will immediately be used by the middleware.
If you have to use other components, you can build this support by yourself by wrapping the existing auth middlewares into a new one and handle the instances internally. (You can create a middleware which handles the config(s) and calls the auth middleware one-after-another with each config...etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With