You have a couple of options. You can intercept the request and store the current page URL in the session storage, if your framework supports it. This involves saving the URL in the user’s session data on the server side, tied to a specific session ID. After authentication, you retrieve this URL from the session and redirect the user back to their initial page.
Alternatively, you could encode the URL information in the state
parameter during the /authorize
request. This could be a JSON object or a JWT, which is then Base64URL encoded. Post-authentication, you decode the state
parameter, extract the original URL, and use it for redirection.
Whichever method you choose depends on your app setup. Just make sure to keep your state
parameter and session data secure to avoid any potential security issues.