My problem is as follows: We have customers who want to login to our app using Azure AD (Microsoft work accounts). Due to organizational issues, it is impossible to set our tenant to act as a hub, where we have app registration and just invite other tenants to join their users to ours.
Instead, what we had to do is to just login to customer tenant (we have access). So, we created app registration directly in customer tenant, set our app with this app registration tenant id, client id, client secret, and logging users from that tenant works just fine.
I understand that it's not ideal. However now a second customer shows up, which will work in the same way. Now, the problem is how to handle changing client id and client secret at runtime? Authority can be set to common, so it will find correct tenant by user email provided, however, in order to authenticate, I have to know where the user is coming from (customer A or customer B) and then set clientId and clientSecret for that request based on that.
At the moment, I have middleware registered in OWIN (app.UseOpenIdConnectAuthentication) but I have to set it up with some values at startup time from config. I tried to use event "RedirectToIdentityProvider" but changing values there just doesn't seem to work - they are always the same since creating the middleware.
How can I make it work correctly, and authenticating users from both customers to their own respective app registrations?