We currently have 4 servers that are being served by Auth0 (dev, qa, staging, production). Opening our web address redirects to the Auth0 login page. The redirect URL contains, along with the Auth0 state, the following parameter: redirect_uri. This is the URL the system will redirect to when you successfully log in. Each server sets this parameter, so the login redirects correctly to the relevant server.
All this works fine.
We have now reached a point where we need to create a second (regional) production server (for the US). What we want to be able to do is to have the users log in to the main production server, and based on a metadata field in the user, it will decide which server to redirect to.
To do so, we implemented a redirect rule. The idea was to take the URL we are on now (the Auth0 URL with the Auth0 state), update the redirect_uri in it to the correct server, and redirect to it. This essentially skips the page in the middle (which we don’t need) and will make the login redirect to the correct server.
The problem we’re facing is that we can’t seem to be able to get the current URL. Without access to the current state, we can’t correctly modify it or redirect to it.
Is there a simple way to get it?
Is there some other way to implement the functionality we’re after?
We did not. We wanted to be able to have a single login page for both servers. We did not find a way to do this. Each of our servers has its own login page.
You could use a rule to redirect the user to the login page/endpoint for the server you want them to log into. Essentially start the authorization flow over using the correct server resulting in the correct redirect url.
You could potentially check the metadata before initiating the authorization flow and set the redirect url differently based on your data in the metadata.
I don’t believe it’s possible to change or even access the redirect uri from within rules though.
As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!