caseproof / members

Members WordPress plugin.
GNU General Public License v2.0
78 stars 35 forks source link

Compatibility issue with auth0 #83

Closed JUVOJustin closed 1 year ago

JUVOJustin commented 1 year ago

When using the member plugin together with the auth0 plugin an infinite redirect loop is created.

The member plugin is configured to create a "private website". Meaning the plugin redirects as supposed to the login page, which in this case leads to getting redirected to the auth0 login page. When successfully authenticated there the user gets redirected to wordpress with some keys as parameters. I think at this point, members redirects the user back to the login page before the auth0 plugin can check for the parameters and set the auth cookie.

JUVOJustin commented 1 year ago

Was able to validate and solve this with the following code:

add_filter('members_is_private_page', function(bool $is_private) {

      // Check if installed. Different constants for v4 and v5 of auth0 wordpress plugin
      if (!defined('WP_AUTH0_VERSION') && !defined('WPA0_VERSION')) {
          return $is_private;
      }

      // Check for url parameters
      if (
          empty($_GET['auth0']) || $_GET['auth0'] != "1"
          || empty($_GET['code'])
          || empty($_GET['state'])
      ) {
          return $is_private;
      }

      return false;
});