wpCAS

From Wikipedia:

The Central Authentication Service (CAS) is a single sign-on protocol for the web. Its purpose is to permit a user to log into multiple applications simultaneously and automatically. It also allows untrusted web applications to authenticate users without gaining access to a user’s security credentials, such as a password. The name CAS also refers to a software package that implements this protocol.

wpCAS integrates WordPress or WordPressMU into an established CAS architecture, allowing centralized management and athentication of user credentials in a heterogeneous environment. Authorization of that user’s capabilities is based on native WordPress settings and functions. CAS only authenticates that the user is who s/he claims to be.

Read more, including installation instructions, in the WordPress Plugins Directory.

What happens when users attempt to login?

Users who attempt to login to WordPress are redirected to the central CAS sign-on screen. After the user’s credentials are verified, s/he is then redirected back to the WordPress site. If the CAS username matches the WordPress username, the user is recognized as valid and allowed access.

If the CAS user does not have an account in the WordPress site, an administrator defined function can be called to provision the account or do other actions. By default, CAS users without WordPress accounts are simply refused access.

Can this plugin provision users in WordPress who are authenticated via CAS?

wpCAS makes allows you to call a function to do that, but each environment is different; each environment probably needs its own solution for this. I’ll post the script I use for that soon.

Download & installation

The plugin is hosted in the WordPress Plugins Directory. Look there for download and installation instructions.

Hey, isn’t that…?

This plugin is based in huge part on Stephen Schwink‘s CAS Authentication plugin and would be a lot different if I couldn’t lean on Stephen’s excellent work. My primary reasons for branching (under the the terms of the GPL) were that I wanted it to work better with WPMU. And, I needed an easier way to hook-in functions to provision users and wanted to do that while also making it easy to upgrade using SVN (thus the config file).

60 thoughts on “wpCAS

  1. Hi Casey – great work on the plugin, got it working first time on a standalone WP installation and looking at implementing it across our some of our WMPU setup, but need to work a bit on managing users. Have you got any examples of provisioning for new users (ie creating a new user in WP if they are authenticated on CAS) or maybe translating some authenticated users to a generic user (one already set up on WP?)

  2. Hi Casey, great work.
    Let me suggest a little improvment. I’ve found that the “redirect” works better if you modify wpcas.php as follow:

    if ( $user = get_userdatabylogin( phpCAS::getUser())){ // user already exists
    // the CAS user has a WP account
    wp_set_auth_cookie( $user->ID );
    // Standard redirect
    if( isset( $_REQUEST['redirect_to'] )) {
    wp_safe_redirect( $_REQUEST['redirect_to'] );
    exit();
    }
    // Default redirect to the admin home page
    //wp_safe_redirect( admin_url() );
    wp_safe_redirect( ‘/wp-admin/’ );
    exit();
    }else{

    I hope this helps,
    Luigi

    • This was enormously helpful. I had a reauth=1 redirect loop that was driving me nuts, and this solved it!

    • @balecan:
      My suggestion is to turn one (or more) of your CAS users into an admin. In WPMU that means going to your WPMU Site Options (site.net/wp-admin/wpmu-options.php) and entering in the user name in the Site Admins field.

  3. I’ve come across a little issue when using the wpcas-conf.php file with WordPressMU:

    1) wp-settings.php loads the modules from wp-content/mu-plugins/ using opendir() and readdir(), not necessarily in alphabetical order (not sure what it goes by). There’s no guarantee that the wpcas-conf.php file is read before or after the wpcas.php file. In our case it does read it prior to the wpcas.php file with an “include_once”.

    2) Then the wpcas.php file tries to include the wpcas-conf.php file again with a simple “include”. This crashed the execution of wpcas.php without further notice in PHP 5.2.6.

    I’ve changed the “include” to “include_once” in wpcas.php and it works fine now.

  4. Pingback: » WordCamp Higher Ed, Northeast MaisonBisson.com

  5. With 1.04 and 1.05, we have found that users cannot alter their own profiles, at least with WP 2.7. It turns out that user-edit.php clears out the value of pass1 when the document finishes loading so users get presented with these when they submit their changes:
    ERROR: You entered your new password only once.
    ERROR: Please enter the same password in the two password fields.

    I’ve had more luck not even having show_password_fields() put in pass1 and pass2 input fields, and generating a random password with the check_passwords() hook.

  6. HI Mr Bisson,

    thank you for the wpcas great plugin, i’ve a question:
    i am implementing your plugin with my wpmu and cas server, but the problem is when a search engine(google) search the content of my site it did not show, i cannot verify the google webmaster with them and they said it because my wpmu blog are redirecting to cas server and go back to the blog and the blog header always redirect to cas server header you can look it here http://web-sniffer.net/?url=http%3A%2F%2Fblog.binusian.org&submit=Submit&http=1.1&type=GET&uak=0, here is the forum http://www.google.com/support/forum/p/Webmasters/thread?tid=19df421f463b942a&hl=en -> Question: verification failed on wpmu . Does your plugin always redirect to the cas server even the user did not login ? or i have to custom the wpcas like http://www.andrejciho.com/wordpress-mu/wpmu-cas-integration/#before

    Regards,

    Adityo

  7. hi ,

    i think i have fixed the problem, before i use wpcas plugin 1.03 and i changes it to 1.05 , copy the CAS.php and CAS folder that consist of client.php, domxml-php4-php5.php , languages and PGTStorage to/wp-content/mu-plugins/wpcas but i got this error when i tried to login to wp-login
    wpCAS plugin not configured
    then i comment wpcas.php line 57 -> /*$wpcas_options['server_path'] == ” ||*/
    and i manage to login and googlebot manage to crawling the website http://web-sniffer.net/?url=http%3A%2F%2Fblog.binusian.org&submit=Submit&http=1.1&type=GET&uak=0. Thank you,

    Regards,

    Adityo

  8. adityo, I had the same problem turns out I didn’t have pear:DB installed.

    Now I am getting the following error:

    [Thu Apr 09 08:02:34 2009] [error] [client 137.99.80.37] PHP Warning: DOMDocument::loadXML(): Empty string supplied as input in /opt/blogs/wordpress-mu/wp-content/plugins/wpcas/domxml-php4-php5.php on line 42

    I have verified that I have a valid CAS ticket.
    The function on line 42 is domxml_open_mem($str) and only places this function is called:

    client.php: if ( !($dom = domxml_open_mem($text_response))) {
    client.php: phpCAS::trace(‘domxml_open_mem() failed’);
    client.php: if ( !($dom = @domxml_open_mem($cas_response))) {
    client.php: phpCAS::trace(‘domxml_open_mem() failed’);
    client.php: if ( !($dom = domxml_open_mem($text_response))) {

    Help!!

  9. I figured out the problem. After sniffing the traffic I realized that the CAS admin gave me the wrong path (1..0). I corrected the path and now CAS authenticated me! Thanks for a great module.

    • “CAS admin gave me the wrong path (1..0)”

      The wrong path to what? CAS.php. I’m getting the same error “wpCAS plugin not configured” with a MU install. I’ve moved CAS and it dirs around, changed the wpcas-conf several times with no luck.

  10. Pingback: » CAS Is A Standard Protocol, Not A Standard Application MaisonBisson.com

  11. I’m having trouble with 1.06.

    I think the problem is the new die() command on line 105 of wpcas.php. It looks like you meant for it to go with the if statement on line 103, but you forgot to add brackets to the if statement.

  12. We are using your library and after login it is returning to the wp-login.php it gives just a blank screen. If I remove the wp-login.php it takes me to the main blog page and I am authenticated. If I disable the plugin, it redirects correctly but of course without the cas login. Do you have any idea of what could be going wrong? Also, what is the simplest way to change the cas/logout?url=http://example.com/blogs to be cas/logout?service=http://example.com/blogs ? When enabled on the CAS server, this will enable the logout to send you back to the blog unauthenticated. The plugin is really nice other than these 2 things. Well done!
    Thanks

    • @Sherwon Harris: I just released a new version that should fix that bug. Please share feedback either way.

      I like your logout suggestion. I’ll try to integrate that in the next version.

  13. Hello,

    I would like to know if anyone tried to mix the CAS and the basic WordPress authentication.

    I have this need but don’t know how to do … please help.

    Thanks by advance.

  14. Hi,
    ( first, sorry for my poor english, I’m french )

    I’ve tested your plugin for a few days and I like it. I just want to know where I can subscribe to be alerted when a new version is available. Comments RSS on this page ?

    Thanks.

    Neoh

  15. Hi,,
    i did as described in the installation manual, but I don’t get it running. I get this error message: “Class ‘phpCAS’ not found”. It looks like the include of the CAS.php is missing. But adding an include causes this error: “phpCAS error: phpCAS::isAuthenticated(): this method should not be called before phpCAS::client() or phpCAS::proxy()”. I think I am missing something, but don’t know what…

    Cheers,

    Rouven

  16. Pingback: » My WordCamp NYC Talks MaisonBisson.com

  17. Could someone post an example of a working directory structure for phpCAS and wpCAS? The install instructions for MU say to place the wpcas.php and wpcas-conf.php in wp-content/mu-plugins/. I cant see that this has any effect other than when they are in mu-plugins only and not plugins the wpCas isnt listed as an installed plugin.

  18. Hi,

    For me the plugins in the mu-plugins folder is not displayed on the WP admin interface. In this folder, all the plugins are activated. But I agree it’s not easy to know if all a plugins works fine.

    I have :
    /wordpressmu
    /wordpressmu/mu-plugins
    /wordpressmu/mu-plugins/wpcas
    /wordpressmu/mu-plugins/wpcas.php
    /wordpressmu/mu-plugins/wpcas-conf.php
    /CAS/CAS.php

    don’t forget to configure path to CAS.php in wpcas-conf.php

    Best regards,
    Neoh

    • Thanks Neoh thats helpful.

      I have everything in:

      wp-content/plugins/wp-cas/
      wp-content/plugins/wp-cas/CAS/

      Still not sure what the value of the wp-content/mu-plugins is? Oh well, i got it working.

      Thanks again.
      Mike

  19. While trying to get the original cas-authentication plugin to work, I came across your plugin. I’m trying to configure it on 2.9.1 and am having problems with user-new.php. It looks like the password fields are getting cleared again? I’m not super familiar with all the hooks, so I don’t know if there’s one that could write the random password later in the process after the page clears the values. Or maybe it’s just a problem on my site. Could it have anything to do with the password strength checker? Any help is greatly appreciated, and thanks for all the work you’ve already done!

  20. This is working on 2.9.1 for me. I modified to wpcas_nowpuser function to automatically create a new user account in wpcas-conf.php:
    function wpcas_nowpuser( $user_name ){
    $mail_suffix = ‘@mail.gatech.edu';
    $default_role = ‘administrator'; // or ‘adminsitrator’/’editor’/’contributor’/’subscriber’
    require_once(ABSPATH . WPINC . ‘/registration.php’);

    /* Create a new user account */
    $user_id = username_exists( $user_name );
    if ( !$user_id ) {
    $user_email = $user_name.$mail_suffix; // generate email string
    $random_password = wp_generate_password( 12, false );
    $user_id = wp_create_user( $user_name, $random_password, $user_email );
    $user = new WP_User($user_id);
    $user->set_role($default_role);
    wp_redirect( site_url( ‘/wp-admin/’ ));
    } else {
    // $random_password = __(‘User already exists. Password inherited.’);
    die(‘Something went horribly wrong. Maybe I am a teapot?’);
    }
    }

  21. I had exactly the same problem as Ben Stoutenburgh: creating new users in the admin interface failed because of the Javascript-blanked pass1 hidden input. So, I decided to fix it in a more elegant way. I have taken out the hidden fields and added an action to set a random password when the form is submitted.

    === modified file ‘wpcas.php’
    — wpcas.php 2010-03-24 23:50:59 +0000
    +++ wpcas.php 2010-03-25 02:16:13 +0000
    @@ -81,8 +81,13 @@
    add_action(‘password_reset’, array(‘wpCAS’, ‘disable_function’));
    add_filter(‘show_password_fields’, array(‘wpCAS’, ‘show_password_fields’));

    +add_action(‘check_passwords’, array(‘wpCAS’, ‘check_passwords’),10,3);
    +
    class wpCAS {

    + function check_passwords($user, $pass1, $pass2) {
    + $random_password = substr( md5( uniqid( microtime( ))), 0, 8 );
    + $pass1=$pass2=$random_password;
    +}
    /*
    We call phpCAS to authenticate the user at the appropriate time
    (the script dies there if login was unsuccessful)
    @@ -90,7 +95,7 @@
    */
    function authenticate() {
    global $wpcas_options, $cas_configured;

    +
    if ( !$cas_configured )
    die( __( ‘wpCAS plugin not configured’, ‘wpcas’ ));

    @@ -136,15 +141,6 @@

    // hide password fields on user profile page.
    function show_password_fields( $show_password_fields ) {
    – if( ‘user-new.php’ basename( $_SERVER['PHP_SELF'] ))
    – return false;

    – $random_password = substr( md5( uniqid( microtime( ))), 0, 8 );

    -?>
    -<input name="pass1" type="hidden" id="pass1" value="” />
    -<input name="pass2" type="hidden" id="pass2" value="” />
    -<?php
    return false;
    }

  22. Hey I’m having some issues with the followup to the CAS login. Once I login to my cas server, I’m redirected back to site.com/wpmu/wp-login.php?ticket=TICKETSTRING, but it’s just showing a blank screen. Unlike Sherwin Harris who posted a similar error last year, if I go to the main blog page after this I am not authenticated.
    Any idea what’s up? Did I miss a config step somewhere?

    Currently using:
    RubyCAS for cas auth
    r221642 of wpcas.php
    v1.1.0 of phpcas by ja-sig
    v2.9.1.1 of WordPress MU

    • Found out what the issue was, didn’t have libcurl installed. Works fine now linux-side.
      New issues though are that phpCas fails to authenticate the user after a successful login after I tried to migrate the entire package to windows/IIS – while I know that at this point it’s outside of the realm of wpcas, anyone had any issues with this before?

  23. First, I love this plugin, thank you! Second, I know that WordPress 3.0 was only just released today but I’m wondering if anyone has tried it under 3.0 and/or if there are plans to update this plugin? This plugin would definitely be a show stopper for us if we couldn’t get it to run under 3.0.

    • wpCAS works with WordPress 3.0 — generate lots of errors in debug mode though. A better programmer than myself should probably fix that. I tried a little bit and was only able to get rid of a few of them.

  24. we are thinking about install the spCAS and is most concerned about the ability to set permissions on commenting in general. Can the comments in WordPress be set up so that users who are members of a certain group are allowed to comment directly while members who are in a different group must have their comments reviewed?
    thanks

    • Pardon me for butting in… wpCAS only authenticates your users. How you create them is up to you and your ldap provisioning script and commenting system. It would be challenging to set this up, but not, I think, impossible. You would need to have some kind of table of groups, and add users to groups at time of provisioning (and manually for existing users, no doubt), then you’d need to check that table at comment post time. Good luck with that.

  25. Hi there. I got the latest version of the plugin working with WordPress 3.0.1. The authentication works well, there’s just one small issue. The password reset fields are no longer available from the edit user profile page. If I uninstall the plugin, the fields are once again visible. Is this a known feature that I need to make a configuration change for? I’m a java programmer with zero php experience, so I haven’t tried to debug the php code.

  26. Hi Casey,
    Thanks for your great work.
    I ‘m using wpcas with a WPMU install (3.0.1) with domains (i.e. the domain is blogs.laclasse.com, and the system creates blogs under this domain : mybeautifulbolg.blogs.laclasse.com, for example). The system works perfectly ! It creates users, blogs end gives roles on the fly, with my provisionning php file.
    I ‘ve seen a problem with login/logout, when I want to do this from ‘mybeautifulbolg.blogs.laclasse.com’ : this does not redirect to my CAS server, however the login/logout works perfectly on ‘blogs.laclasse.com’.

    How can I activate wpCAS on sub-domains ? Did I miss something ?

    • Ouch ! Sorry for this dummy question ! I just had to activate wpCas Plugins on the network, and not only on the first blog…
      Thanks for this plugin which works fine.

      I have a complete provisionning php system which creates users and/or blogs if needed, with default parameters for each. If someone is interested I can publish some functions. This is working with CAS2 cleint (wiich send others attributes than only ‘user’ attribute).

      • I’ve just started using wpcas and would be grateful for any help with provisioning user accounts. Pilooz, or anyone else, do you have any scripts or tips you can share?

        Thanks

  27. Single sign out and WordPress

    phpCAS version 1.1.3
    wpcas version 1.07
    Wordpress version 3.0.1

    I’m adding WordPress to a site that uses CAS single sign on/out. Everything works well except signal sign out from WordPress. If I open two pages/tabs in the browser and logout from one (a java portlet page) the CAS server sends out the logout request to all logged in clients. I catch this in wpcas with a call to phpCAS::handleLogoutRequests which handles the logout request, here’s some of the phpCAS::trace

    D8FD .START phpCAS-1.1.3 ****************** [CAS.php:471]
    D8FD .=> phpCAS::client(‘2.0′, ‘cas.internal’, 443, ‘/cas/’, true) [wpcas.php:71]
    D8FD .| => CASClient::CASClient(‘2.0′, false, ‘cas.internal’, 443, ‘/cas/’, true) [CAS.php:374]
    D8FD .| <= ''
    D8FD . include_once(‘/var/www/20101108_1300_blog/wp-content/plugins/wpcas/wpcas.php’) [wp-settings.php:175]
    D8FD .| => CASClient::handleLogoutRequests(true, array ( 0 => ‘cas.internal’, 1 => ‘10.1.1.72’,)) [CAS.php:1041]
    D8FD .| | Logout requested
    D8FD .| | SAML REQUEST: @NOT_USED@ST-538-LvawXr7BrxeSeUtxxvz3-cas
    D8FD .| | Client: 10.18.1.72/10.1.1.72
    D8FD .| | Allowed client ‘cas.internal’ does not match
    D8FD .| | Allowed client ‘10.1.1.72’ matches, logout request is allowed
    D8FD .| | Ticket to logout: ST-538-LvawXr7BrxeSeUtxxvz3-cas
    D8FD .| | Session id: ST538LvawXr7BrxeSeUtxxvz3cas
    D8FD .| | exit()
    D8FD .| | –
    D8FD .| –

    Even though ‘handleLogoutRequests’ clears the cookies on the server, because it’s not returning to the client in that call, the client still has it’s cookies set, and subsequent calls to the server from that browser, send these cookies back in the headers. WordPress uses the cookies to authenticate the client, and so it remains logged in.

    If anyone has any ideas, or has this already working, I would be interested in your views and/or opinions.

  28. Hello! Thanks for the plugin!
    With the new version of CAS 1.2.2, it is needed that the phpCAS::client call would specify “false” for session creation, here’s the patch that works for me (around line 66):

    if ($cas_configured) {
    phpCAS::client($wpcas_options['cas_version'],
    $wpcas_options['server_hostname'],
    intval($wpcas_options['server_port']),
    $wpcas_options['server_path'],
    false); <— LINE 66, add "FALSE", phpCAS do not let phpcas do start_session

    // function added in phpCAS v. 0.6.0
    // checking for static method existance is frustrating in php4

  29. hey!
    i’ve useing wpcas in wordpress 3.3.1 with extranet and have some trouble with authentication with frontend proxy service.

    if i add the “false” in wpcas-w-ldap.php i ran into a redirect loop of wp-login.php and could not authenticate proper.

    if’ve added ip-ranges for public and cas auth required access. (apache mod_auth_cas)

    on the publicip-access side i can sucessfull login to apache site with cas.
    when i login to wordpress (using cas) i also get into a wp-login.php loop ;-(

    this all had worked in wordpress 3.3.0 – the problem comes with 3.3.1.
    i know in 3.3.1 some security relevated issues depanding redirects have been fixed…

    any ideas??

  30. wpCAS is working for existing users (under WordPress 3.5.1), but when I try to create a new user I get:

    ERROR: Please enter your password.

    The last time I created a user as about 6 months ago (so WP 3.4 maybe?). Any ideas where I should look?

    • I have a fix for the create user problem (I think the issue was a change from PHP 5.3 to PHP 5.4):

      On line 149, change

      function check_passwords( $user, $pass1, $pass2 ) {

      to
      function check_passwords( $user, &$pass1, &$pass2 ) {

      and then creating a user works again.

      There is another issue, If wpCAS is already activated, it works fine. If I deactivate it and then attempt to activate, I get:

      phpCAS error: phpCAS::client(): Another session was started before phpcas. Either disable the session handling for phpcas in the client() call or modify your application to leave session handling to phpcas in /vhome/newsdev/htdocs/wp-content/plugins/wpcas/wpcas.php on line 65

      I have not looked into this issue.

  31. Mr. Bisson,
    Thank you for your great work on this plugin!
    Please help:
    Our department uses WordPress for our website at perf.tamu.edu, and we have been using the wpCAS plugin you developed for log-ins with our university accounts. Recently, we wanted to open up one of our sites for students with our university accounts without WordPress authentication. So we first duplicated the plugin to edit and activate on that site, but found out that we can’t due to the network activation of the original one. We then proceeded to network deactivate the original plugin in hopes to activate it separately on each of our sites. However, now we get error messages and can’t activate the plugin at all. We are in great need for help. Please provide us with any advice you may have. Anything will be greatly appreciated.

    • I apologize, but I am unable to offer any support for wpCAS. I’m no longer working in a field that demands it, or even offers an opportunity to test it. I’d suggest a WordPress agency such as http://10up.com as the best path forward if you don’t have local expertise to work through any bugs.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">