OAuth2 – How to Set Dynamic Redirect URL After Logout from Experience Cloud

auth-providerexperience-cloudoauth2

The setup for my issue happens in a digital experience. We use an external SSO System to provide credentials, so Salesforce is the relying Party.

What I want to achieve is, that after the Person logs out, depending on a language they should be redirected to the specific site.
Examples:

  1. https://logoutpage.com/en
  2. https://logoutpage.com/fr

Currently with the standard Custom Logout URL within the auth. Provider it works for a single generic URL. As an example the Custom Logout URL could look like this:

So whenever we would Logout we'd be redirected to the first option.

As an Idea I tried to find a way to replace the standard logout action within the experience Cloud with external URL's which would kind of logout from the systems sequentially utilizing redirect URL's. But I was not able to find a way to do that.
This is how I imagined it to look like:

Is this even possible to realize? Is there something that I didn't find in my research that helps me in this case?

Best Answer

Meanwhile I found a workaround to that.

One crucial Idea was missing to me at that time. It's that when you remove the Custom Logout URL from the Auth. Provider, you will have no redirect from /secur/logout.jsp.

Utilizing this enables me to manually call the /secur/logout.jsp from my lwc and afterwards redirecting the window to another URL, which then is the custom URL I want to have with the correct redirect. I just then had to dynamically set the button settings which URL to use and this was working fine.

One additional to the redirect, sadly it's not possible to use the Navigation Mixin, as this always opens a new tab for external URLs. Which leads to the scrappy example code.

async handleLogout() {
    await fetch('https://mycommunityurl/secur/logout.jsp');
    window.location.replace(this.logoutUrl);
}

Mind that this.logoutUrl is set by some of our configuration which would be hard to put into this example. Instances of that would be "https://my-sso-provider.com/logout?redirectURL=https://logoutpage.com/en" or "https://my-sso-provider.com/logout?redirectURL=https://logoutpage.com/fr"

Related Topic