• Resolved sornman

    (@sornman)


    Ok, here is the issue:

    I am currently using authorizer_allow_login to check if the CAS user exists in WP, if not then if the user exists in LDAP, if so, programmatically log into dummy account, ‘cas_user’, to access private portions of the site. This is an account just for reading and don’t want to create thousands of accounts that will need to be regularly audited. This all seems to be working properly, the issue is that the programmatically logged in users are not being sent to the CAS logout.

    $cas_user = array(
      'user' => 'cas_user',
      'role' => 'cas_role'
    );
    
    add_filter('authorizer_allow_login', function ($allow_login, $user_data) {
      $cas_user = $GLOBALS['cas_user'];
      if (username_exists($user_data['username'])) return true;
      if (!search_ldap_user($user_data['cas_attributes']['UID'])) return false;
      if ($user = get_user_by('login', $cas_user['user'])) {
        clean_user_cache($user->ID);
        wp_clear_auth_cookie();
        wp_set_current_user($user->ID);
        wp_set_auth_cookie($user->ID);
        update_user_caches($user);
    
        if ($_GET['redirect_to']) $redirect_to = $_GET['redirect_to'];
        else $redirect_to = site_url();
    
        wp_safe_redirect($redirect_to);
        exit();
      }
    }, 10, 2);

    So the user gets logged in properly. Why isn’t Authorizer logging them out the same way it does actual WP users?

    Thanks!

    • This topic was modified 3 years, 7 months ago by sornman.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using authorizer_allow_login to programmatically login, doesn’t CAS logout’ is closed to new replies.