Hi,
I finally managed it with cookies and no changes on OIDC setup :
- add script to theme\web\login.html (bellow)
- add a nanoflow on the page after redirect and add a dataview with data source a nanoflow that executes the javascript
## page after redirect
var redirectUrl = '';
let value = "; " + document.cookie;
let parts = value.split("; " + 'redirect-url' + "=");
if (parts.length === 2) {
redirectUrl = parts.pop().split(";").shift();
//remove the cookie
document.cookie = 'redirect-url=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
window.location.href = redirectUrl;
}
## script to theme\web\login.html
<script>function getBaseURL(url) { const regex = /^(https?:\/\/[^\/]+)/; const match = url.match(regex); var url = match ? match[1] : ""; if (url.endsWith('/')) { url = url.slice(0, -1); } return url;}
function setCookie(name, value, days) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/";} function removeStartingSlash(text) { return text.replace(/^\/+/, '');}
function extractFragment(url) { var arr = url.split('#'); if(arr.length > 1){ return removeStartingSlash(arr[1] || ""); } return "";}
const baseUrl = getBaseURL(window.location.href);//http://localhost:8080/login.html#/OpenOffer/13 => http://localhost:8080const fragment = extractFragment(window.location.href);//OpenOffer/13const redirectUrl = baseUrl + "/p/" + fragment;if(fragment != ''){ setCookie("redirect-url", redirectUrl, 1);} </script>
Hi Sebastien,
I'm facing a smiliar issue and wondering if you go eloborate on how you solved this.
Hi,
This is usually not an OIDC configuration problem itself. The original URL needs to be preserved through the OIDC login flow.
If you are using Mendix 10.6+, the recommended approach is to use the built-in Page URL / Microflow URL functionality instead of the deprecated Deep Link module. Mendix explicitly supports Page and Microflow URLs with OIDC SSO and redirects the user back to the requested URL after successful authentication.
For example, if the microflow has a URL like:
https://myapp.com/mf/myMicroflow
the flow should be:
User opens Microflow URL
↓
OIDC authentication
↓
IdP login
↓
Mendix OIDC callback
↓
Original Microflow URL is restored
↓
Microflow executes
LoginLocation constant./oauth/v2/login?cont=
The important part is the trailing = because the original deep-link URL is appended to the cont parameter.
For example:
/oauth/v2/login?cont=<original-url>
One more important point: if the microflow URL is supposed to execute a microflow and then open a page, Mendix supports that behavior—the microflow runs during client startup, and if it contains a Show a page action, that page is opened instead of the home page.
So the key is: don't configure OIDC to redirect simply to the default index.html; preserve the original Page/Microflow URL through the authentication continuation (cont) flow.