Logout Error: post_logout_redirect_uri Parameter Not Defined as a Valid URL

Overview

When logging out of the application, the following error appears:
 

"invalid_request: The "post_logout_redirect_uri" querystring parameter "https://<DOMAIN>/v2/logout?client_id=ABC&returnTo=<INVALID URL>" is not defined as a valid URL in "Allowed Logout URLs". To add a new URL, please do it here: https://manage.auth0.com/#/applications/<client_id>/settings"

<INVALID URL> represents a URL already added to the list of the Allowed logout URLs in the application settings tab.

 

Applies To
  • Allowed Logout URLs
Cause

While using the oidc/logout endpoint, the value for post_logout_redirect_uri must EXACTLY match one of the URLs in the Allowed Logout URL list in the application; when using the /v2/logout endpoint, this requirement is not needed because the query parameters in the redirect URL are not taken into account.

Due to the query parameters and the use of the /oidc/logout endpoint, it is possible that the URL value in production does not EXACTLY match any of the allowed logout URLs in the client application settings.

See Add parameters to post-logout redirect URL for more details.

Solution

The code below is an example of the issue:
 

async logout(req, res) {
  try {
    const logoutUrl = [
      `${process.env.AUTH0_ISSUER_BASE_URL}/v2/logout?`,
      `client_id=${process.env.AUTH0_CLIENT_ID}`,
      `&returnTo=${process.env.AUTH0_BASE_URL}`,
    ];
  await handleLogout(req, res, {
    returnTo: logoutUrl.join(''),
  });
  } catch (err) {
    res.status(err.status ?? 500).end(err.message);
  }
  },
// other auth handlers
});


This was causing the returnTo parameter to have query parameters that could have been removed by changing the code, for example, to:
 

async logout(req, res) {
  try {
    await handleLogout(req, res, {
      returnTo: ${process.env.AUTH0_BASE_URL},  //This URL could have also been harcoded.
    });
  } catch (err) {
    res.status(err.status ?? 500).end(err.message);
  }
  },
// other auth handlers
});

Recommended content

No recommended content found...