Automatically detect organization for login by redirect uri

Is there a way to automatically detect / set the organization for the login page?

For example, each of our customers has its own custom domain where the user is redirected to after login, so the organization could be selected based on the redirect url.

Is there any way to do this? As far as I can see, I don’t see a possibility to execute actions or custom rules that are run before the login page is displayed that I could use to set the org id.