Skip to content

Instantly share code, notes, and snippets.

@JASchilz
Last active June 1, 2018 17:07
Show Gist options
  • Save JASchilz/70d6f9fa82ffb3a4372d to your computer and use it in GitHub Desktop.
Save JASchilz/70d6f9fa82ffb3a4372d to your computer and use it in GitHub Desktop.
Instructions for UWNetID Wordpress Login @uw

UWNetID WordPress Login @UW

Introduction

The basic flow of UWNetID WordPress login is:

  1. Use an .htaccess file to "protect" the login/admin files, via PubCookie or Shibboleth.
  2. User is directed to https://weblogin.washington.edu/ to authenticate.
  3. When they return, their UWNetID is provided to Php through the $_SERVER["REMOTE_USER"] variable. A plugin checks this variable against the set of WordPress usernames and logs the end user in to a matching user.

Requirements

To use UWNetID login, you must:

  1. Be able to create and edit files within your WordPress directory.
  2. Be able to install a plugin.
  3. Be on a UW-IT provided server. It may be possible to use UWNetID login if you're not on a UW-IT provided server, but you'll have to have server administration skills and permission to connect to UW-IT's authentication services.

Deficiencies, Dangers, and Mitigation

The WordPress plugins available for handling this process have not been updated in 2+ years. This introduces security concerns into authentication, which is a security-critical process.

To mitigate this risk, this guide UWNetID-whitelist protects all login and admin files: user access to login and admin are whitelist restricted at the web-server level. To my own satisfaction, this means that if the plugin we're using does introduce vulnerabilities, only those users in my whitelist will have an opportunity to exploit it.

This solution does preclude mixed login, in which some users authenticate via UWNetID and some users authenticate via traditional WordPress login: everyone must have a UWNetID to login. It must certainly be possible to implement mixed login securely, but this guide does not address that challenge.

Also note that because the relevant plugin is old and unmaintained, we have to implement a couple of work-arounds. Also, any new update to WordPress could potentially break the plugin.

Shibboleth vs. PubCookie

Shibboleth and PubCookie are two schemes for user authentication. If you are on a UW-IT managed server, then Apache probably has a module for one or the other installed. You probably do not have a choice as to which one to use.

For web development, either is invoked through .htaccess authentication. For example, protecting a directory under Shibboleth:

  AuthType Shibboleth
  ShibRequireSession On
  Require valid-user

Protecting a directory under PubCookie:

  AuthType UWNetID
  PubcookieAppID "My Application"
  Require valid-user

All of the examples below use Shibboleth, but to adapt the example to PubCookie, just replace any occurence of:

  AuthType Shibboleth
  ShibRequireSession On

with:

  AuthType UWNetID
  PubcookieAppID "My Application"

Both schemes are similar in that the user-id is subsequently provided to Php as the $_SERVER["REMOTE_USER"] variable. However, whereas PubCookie will identify a user as javerage, Shibboleth will identify the same user as javerage@washington.edu.

Initial Steps

  1. Install WordPress

  2. Create Initial User

  3. Install HTTP Authentication Plugin

https://wordpress.org/plugins/http-authentication/
  1. Make WordPress Login Trigger UWNetID Login
In your root WordPress directory .htaccess:
```
<Files "wp-login.php">
  AuthType Shibboleth
  ShibRequireSession On
  Require group my_osfa_admin_group
</Files>
```
  1. Protect WordPress Admin
In your wp-admin .htaccess:
```
AuthType Shibboleth
ShibRequireSession On
Require group my_osfa_admin_group
```

Creating Additional Users - Non-Multisite

The HTTP-Authentication plugin attempts to override user creation, but is incompatible with recent versions of WordPress. In order to create a new user, you have to either:

  1. Disable the HTTP Authentication Plugin
  2. Create the New User
  3. Re-enable the HTTP Authentication Plugin
  • or -

    1. Enable Automatically Create Accounts in Settings->HTTP Authentication.
    2. Direct the end-user to visit your wp-login.php page. This will cause HTTP Authentication to create a user for them, with an appropriate username.
    3. Disable Automatically Create Accounts.
    4. Go to user administration, find the created user, and give them the appropriate privileges.

If your login area is protected by a UWNetID whitelist, you may choose to leave Automatically Create Accounts enabled in order to avoid manual user account creation.

Notice that if disable HTTP-Authentication and then log out, you may have a difficult time logging back on: know the WordPress password for your account, or prepare another way of authenticating yourself.

Multisite Plus Shibboleth

For multi-sites, HTTP-Authentication does not override user creation. In fact multi-site plus PubCookie works seamlessly.

However, multi-site plus Shibboleth presents another problem: Shibboleth reports users as javerage@washington.edu, but WordPress only allows alpha-numerics in user names: WordPress will not allow us to create users of the form javerage@washington.edu.

To solve this issue, I had to modify wp-content/plugins/http-authentication/http-authentication.php around line 180 as follows:

$server_keys = $this->_get_server_keys();
    foreach ($server_keys as $server_key) {
            if (! empty($_SERVER[$server_key])) {
                    $username = $_SERVER[$server_key];
            }
    }

    // ADD THE FOLLOWING LINE:
    $username = strtok($username, "@");  // Strip the domain from the username

    if (! $username) {
            return new WP_Error('empty_username', '<strong>ERROR</strong>: No user found in server variables.');
    }

This strips the @washington.edu from javerage@washington.edu, meaning that we can create a user javerage with which Joe Average can administer our site.

@Nogbit
Copy link

Nogbit commented Oct 7, 2015

Thanks!

Another work around for non multisite which doesn't require you to deactivate/re-activate the HTTP Authentication is to use the SQL below, but it does require a connection to the database. This workaround isn't ideal if you are protecting via a group as was demoed today because you would need to run this sql for all members (and new members as they get added to the group).

use wordpress
insert into wp_users(ID,user_login,user_email,display_name) values([next_unused_number],'[netid]','[netid]@washington.edu','[Display_Name]')

Also mentioned was the feasibility of the Shibboleth plugin that I chimed in on in context with registering your off site wordpress (AWS/Azure etc) with UW's Service Provider Registry (see their wiki). But, it seems this plugin is only officially supported up to WP 3.9.9, and it's source code has some open issues (for multisite) that may be of concern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment