Giter Club home page Giter Club logo

wp-saml-auth's Introduction

WP SAML Auth

Contributors: getpantheon, danielbachhuber, outlandish-josh, jazzs3quence
Tags: authentication, SAML
Requires at least: 4.4
Tested up to: 6.3
Requires PHP: 7.3
Stable tag: 2.1.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

SAML authentication for WordPress.

Description

CircleCI Actively Maintained

SAML authentication for WordPress, using the bundled OneLogin SAML library or optionally installed SimpleSAMLphp. OneLogin provides a SAML authentication bridge; SimpleSAMLphp provides SAML plus a variety of other authentication mechanisms. This plugin acts as a bridge between WordPress and the authentication library.

If your organization uses Google Apps, integrating Google Apps with WP SAML Auth takes just a few steps.

The standard user flow looks like this:

  • User can log in via SAML using a button added to the standard WordPress login view.
  • When the button is clicked, the user is handed off to the authentication library. With OneLogin, the user is redirected to the SAML identity provider. With SimpleSAMLphp, the user is redirected to the SimpleSAMLphp install.
  • Once the user is authenticated with the identity provider, they're redirected back to WordPress and signed in to their account. A new WordPress user will be created if none exists (although this behavior can be disabled).
  • When the user logs out of WordPress, they are also logged out of the identity provider.

A set of configuration options allow you to change the plugin's default behavior. For instance, permit_wp_login=>false will force all authentication to go through the SAML identity provider, bypassing wp-login.php. Similiarly, auto_provision=>false will disable automatic creation of new WordPress users.

See installation instructions for full configuration details.

Installation

Once you've activated the plugin, and have access to a functioning SAML Identity Provider (IdP), there are a couple of ways WP SAML Auth can be configured:

  1. Settings page in the WordPress backend. The settings page offers the most common configuration options, but not all. It's located at "Settings" -> "WP SAML Auth".
  2. Code snippet applied with a filter. The code snippet approach, documented below, allows access to all configuration settings. The settings page is disabled entirely when a code snippet is present.

If you're connecting directly to an existing IdP, you should use the bundled OneLogin SAML library. The necessary and most common settings are available in the WordPress backend.

If you have more complex authentication needs, then you can also use a SimpleSAMLphp installation running in the same environment. These settings are not configurable through the WordPress backend; they'll need to be defined with a filter. And, if you have a filter in place, the WordPress backend settings will be removed.

Additional explanation of each setting can be found in the code snippet below.

To install SimpleSAMLphp locally for testing purposes, the Identity Provider QuickStart is a good place to start. On Pantheon, the SimpleSAMLphp web directory needs to be symlinked to ~/code/simplesaml to be properly handled by Nginx. Read the docs for more details about configuring SimpleSAMLphp on Pantheon.

Because SAML authentication is handled as a part of the login flow, your SAML identity provider will need to send responses back to wp-login.php. For instance, if your domain is pantheon.io, then you'd use http://pantheon.io/wp-login.php as your AssertionConsumerService configuration value.

To configure the plugin with a filter, or for additional detail on each setting, use this code snippet:

function wpsax_filter_option( $value, $option_name ) {
    $defaults = array(
        /**
         * Type of SAML connection bridge to use.
         *
         * 'internal' uses OneLogin bundled library; 'simplesamlphp' uses SimpleSAMLphp.
         *
         * Defaults to SimpleSAMLphp for backwards compatibility.
         *
         * @param string
         */
        'connection_type' => 'internal',
        /**
         * Configuration options for OneLogin library use.
         *
         * See comments with "Required:" for values you absolutely need to configure.
         *
         * @param array
         */
        'internal_config'        => array(
            // Validation of SAML responses is required.
            'strict'       => true,
            'debug'        => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
            'baseurl'      => home_url(),
            'sp'           => array(
                'entityId' => 'urn:' . parse_url( home_url(), PHP_URL_HOST ),
                'assertionConsumerService' => array(
                    'url'  => wp_login_url(),
                    'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
                ),
            ),
            'idp'          => array(
                // Required: Set based on provider's supplied value.
                'entityId' => '',
                'singleSignOnService' => array(
                    // Required: Set based on provider's supplied value.
                    'url'  => '',
                    'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
                ),
                'singleLogoutService' => array(
                    // Required: Set based on provider's supplied value.
                    'url'  => '',
                    'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
                ),
                // Required: Contents of the IDP's public x509 certificate.
                // Use file_get_contents() to load certificate contents into scope.
                'x509cert' => '',
                // Optional: Instead of using the x509 cert, you can specify the fingerprint and algorithm.
                'certFingerprint' => '',
                'certFingerprintAlgorithm' => '',
            ),
        ),
        /**
         * Path to SimpleSAMLphp autoloader.
         *
         * Follow the standard implementation by installing SimpleSAMLphp
         * alongside the plugin, and provide the path to its autoloader.
         * Alternatively, this plugin will work if it can find the
         * `SimpleSAML_Auth_Simple` class.
         *
         * @param string
         */
        'simplesamlphp_autoload' => dirname( __FILE__ ) . '/simplesamlphp/lib/_autoload.php',
        /**
         * Authentication source to pass to SimpleSAMLphp
         *
         * This must be one of your configured identity providers in
         * SimpleSAMLphp. If the identity provider isn't configured
         * properly, the plugin will not work properly.
         *
         * @param string
         */
        'auth_source'            => 'default-sp',
        /**
         * Whether or not to automatically provision new WordPress users.
         *
         * When WordPress is presented with a SAML user without a
         * corresponding WordPress account, it can either create a new user
         * or display an error that the user needs to contact the site
         * administrator.
         *
         * @param bool
         */
        'auto_provision'         => true,
        /**
         * Whether or not to permit logging in with username and password.
         *
         * If this feature is disabled, all authentication requests will be
         * channeled through SimpleSAMLphp.
         *
         * @param bool
         */
        'permit_wp_login'        => true,
        /**
         * Attribute by which to get a WordPress user for a SAML user.
         *
         * @param string Supported options are 'email' and 'login'.
         */
        'get_user_by'            => 'email',
        /**
         * SAML attribute which includes the user_login value for a user.
         *
         * @param string
         */
        'user_login_attribute'   => 'uid',
        /**
         * SAML attribute which includes the user_email value for a user.
         *
         * @param string
         */
        'user_email_attribute'   => 'mail',
        /**
         * SAML attribute which includes the display_name value for a user.
         *
         * @param string
         */
        'display_name_attribute' => 'display_name',
        /**
         * SAML attribute which includes the first_name value for a user.
         *
         * @param string
         */
        'first_name_attribute' => 'first_name',
        /**
         * SAML attribute which includes the last_name value for a user.
         *
         * @param string
         */
        'last_name_attribute' => 'last_name',
        /**
         * Default WordPress role to grant when provisioning new users.
         *
         * @param string
         */
        'default_role'           => get_option( 'default_role' ),
    );
    $value = isset( $defaults[ $option_name ] ) ? $defaults[ $option_name ] : $value;
    return $value;
}
add_filter( 'wp_saml_auth_option', 'wpsax_filter_option', 10, 2 );

If you need to adapt authentication behavior based on the SAML response, you can do so with the wp_saml_auth_pre_authentication filter:

/**
 * Reject authentication if $attributes doesn't include the authorized group.
 */
add_filter( 'wp_saml_auth_pre_authentication', function( $ret, $attributes ) {
    if ( empty( $attributes['group'] ) || ! in_array( 'administrators', $attributes['group'] ) ) {
        return new WP_Error( 'unauthorized-group', "Sorry, you're not a member of an authorized group." );
    }
    return $ret;
}, 10, 2 );

WP-CLI Commands

This plugin implements a variety of WP-CLI commands. All commands are grouped into the wp saml-auth namespace.

$ wp help saml-auth

NAME

  wp saml-auth

DESCRIPTION

  Configure and manage the WP SAML Auth plugin.

SYNOPSIS

  wp saml-auth <command>

SUBCOMMANDS

  scaffold-config      Scaffold a configuration filter to customize WP SAML Auth usage.

Use wp help saml-auth <command> to learn more about each command.

Contributing

See CONTRIBUTING.md for information on contributing.

Security Policy

Reporting Security Bugs

Please report security bugs found in the WP SAML Auth plugin's source code through the Patchstack Vulnerability Disclosure Program. The Patchstack team will assist you with verification, CVE assignment, and notify the developers of this plugin.

Frequently Asked Questions

Can I update an existing WordPress user's data when they log back in?

If you'd like to make sure the user's display name, first name, and last name are updated in WordPress when they log back in, you can use the following code snippet:

/**
 * Update user attributes after a user has logged in via SAML.
 */
add_action( 'wp_saml_auth_existing_user_authenticated', function( $existing_user, $attributes ) {
    $user_args = array(
        'ID' => $existing_user->ID,
    );
    foreach ( array( 'display_name', 'first_name', 'last_name' ) as $type ) {
        $attribute          = \WP_SAML_Auth::get_option( "{$type}_attribute" );
        $user_args[ $type ] = ! empty( $attributes[ $attribute ][0] ) ? $attributes[ $attribute ][0] : '';
    }
    wp_update_user( $user_args );
}, 10, 2 );

The wp_saml_auth_existing_user_authenticated action fires after the user has successfully authenticated with the SAML IdP. The code snippet then uses a pattern similar to WP SAML Auth to fetch display name, first name, and last name from the SAML response. Lastly, the code snippet updates the existing WordPress user object.

How do I use SimpleSAMLphp and WP SAML Auth on a multi web node environment?

Because SimpleSAMLphp uses PHP sessions to manage user authentication, it will work unreliably or not at all on a server configuration with multiple web nodes. This is because PHP's default session handler uses the filesystem, and each web node has a different filesystem. Fortunately, there's a way around this.

First, install and activate the WP Native PHP Sessions plugin, which registers a database-based PHP session handler for WordPress to use.

Next, modify SimpleSAMLphp's www/_include.php file to require wp-load.php. If you installed SimpleSAMLphp within the wp-saml-auth directory, you'd edit wp-saml-auth/simplesamlphp/www/_include.php to include:

<?php
require_once dirname( dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) ) . '/wp-load.php';

Note: the declaration does need to be at the top of _include.php, to ensure WordPress (and thus the session handling) is loaded before SimpleSAMLphp.

There is no third step. Because SimpleSAMLphp loads WordPress, which has WP Native PHP Sessions active, SimpleSAMLphp and WP SAML Auth will be able to communicate to one another on a multi web node environment.

Upgrade Notice

2.0.0

Minimum supported PHP version is 7.3.

Changelog

2.1.4 (November 27, 2023)

  • Fix typo in the label for the certificate path [#352]
  • Updates Pantheon WP Coding Standards to 2.0 [#357]
  • Fix logged-out auth issue [#359] (props Snicco)

2.1.3 (April 8, 2023)

  • Fixes missing vendor/ directory in previous release [#336]

2.1.2 (April 7, 2023)

  • Bump yoast/phpunit-polyfills from 1.0.4 to 1.0.5 [#334]
  • Updates tested up to version
  • Removes unused NPM dependencies

2.1.1 (March 15, 2023)

2.1.0 (November 29, 2022)

  • Adds Github Actions for building tag and deploying to wp.org. Add CONTRIBUTING.md. [#311]

2.0.1 (January 24, 2022)

  • Rebuilds platform dependencies to accommodate PHP 7.3 [#278].

2.0.0 (January 6, 2022)

  • BREAKING: Updates onelogin/php-saml to v4.0.0, which requires PHP 7.3 or higher [#275].

1.2.7 (December 9, 2021)

  • Adds a wp_saml_auth_pre_logout action that fires before logout [#274].

1.2.6 (October 12, 2021)

  • Adds a wp_saml_auth_login_parameters filter to allow login parameters to be filtered [#262].

1.2.5 (August 18, 2021)

  • Fixes undefined index notice introduced in 1.2.4 [#257].

1.2.4 (August 18, 2021)

  • Adds a wp_saml_auth_internal_logout_args filter to allow the internal logout args to be filterable [#255].

1.2.3 (May 25, 2021)

  • Adds a wp_saml_auth_force_authn filter to allow forceAuthn="true" to be enabled [#248].

1.2.2 (Apr 26, 2021)

  • Ensures SAML button and explanations are only added to the login screen [#242].

1.2.1 (Mar 2, 2021)

  • Updates onelogin/php-saml to v3.6.1 [#236].

1.2.0 (Feb 22, 2021)

  • Updates onelogin/php-saml to v3.6.0 [#233].

1.1.1 (Feb 3, 2021)

  • Updates French localization and ensures localizations are loaded [#230].

1.1.0 (Dec 1, 2020)

  • Updates onelogin/php-saml to v3.5.0 [#218].

1.0.2 (May 27, 2020)

  • Avoid undesired session_start() when using SimpleSAMLphp [#196].

1.0.1 (May 26, 2020)

  • Allows redirecting back to wp-login.php while avoiding redirect loop [#192].

1.0.0 (March 2, 2020)

  • Plugin is stable.

0.8.3 (February 3, 2020)

  • Removes unused placeholder value that's causing PHP notices [#178].

0.8.2 (January 22, 2020)

  • Fixes method declaration for methods used statically [#176].

0.8.1 (November 25, 2019)

  • Updates onelogin/php-saml to v3.4.1 [#174].

0.8.0 (November 20, 2019)

  • Updates onelogin/php-saml to v3.4.0 [#173].

0.7.3 (November 7, 2019)

  • Updates onelogin/php-saml to v3.3.1 [#172].

0.7.2 (October 30, 2019)

  • Fixes issue where an empty required settings field would throw load Exception [#170].

0.7.1 (September 26, 2019)

  • Fixes typo on the settings page [#163].

0.7.0 (September 16, 2019)

  • Updates onelogin/php-saml to v3.3.0 [#160].

0.6.0 (May 14, 2019)

  • Adds a settings page for configuring WP SAML Auth [#151].
  • Fixes issue when processing SimpleSAMLphp response [#145].

0.5.2 (April 8, 2019)

  • Updates onelogin/php-saml to v3.1.1 for PHP 7.3 support [#139].

0.5.1 (November 15, 2018)

  • Introduces a wp_saml_auth_attributes filter to permit modifying SAML response attributes before they're processed by WordPress [#136].

0.5.0 (November 7, 2018)

  • Updates onelogin/php-saml to v3.0.0 for PHP 7.2 support [#133].

0.4.0 (September 5, 2018)

  • Updates onelogin/php-saml from v2.13.0 to v2.14.0 [#127].

0.3.11 (July 18, 2018)

  • Provides an error message explicitly for when SAML response attributes are missing [#125].

0.3.10 (June 28, 2018)

  • Ensures redirect_to URLs don't lose query parameters by encoding with rawurlencode() [#124].
  • Adds French localization.

0.3.9 (March 29, 2018)

  • Fixes PHP notice by using namespaced SimpleSAMLphp class if available [#118].
  • Updates onelogin/php-saml from v2.12.0 to v2.13.0

0.3.8 (February 26, 2018)

  • Redirects to action=wp-saml-auth when redirect_to is persisted, to ensure authentication is handled [#115].

0.3.7 (February 13, 2018)

  • Persists redirect_to value in a more accurate manner, as a follow up to the change in v0.3.6 [#113].

0.3.6 (February 7, 2018)

  • Prevents WordPress from dropping authentication cookie when user is redirected to login from /wp-admin/ URLs [#112].

0.3.5 (January 19, 2018)

  • Substitutes wp-login.php string with parse_url( wp_login_url(), PHP_URL_PATH ) for compatibility with plugins and functions that alter the standard login url [#109].

0.3.4 (December 22, 2017)

  • Permits internal connection type to be used without signout URL, for integration with Google Apps [#106].

0.3.3 (November 28, 2017)

  • Forwards 'redirect_to' parameter to SAML Authentication to enable deep links [#103].

0.3.2 (November 9, 2017)

  • Updates onelogin/php-saml dependency from v2.10.7 to v2.12.0 [#90, #99].

0.3.1 (July 12, 2017)

  • Passes $attributes to wp_saml_auth_insert_user filter, so user creation behavior can be modified based on SAML response.

0.3.0 (June 29, 2017)

  • Includes OneLogin's PHP SAML library for SAML auth without SimpleSAMLphp. See "Installation" for configuration instructions.
  • Fixes handling of SAMLResponse when permit_wp_login=true.

0.2.2 (May 24, 2017)

  • Introduces a wp_saml_auth_login_strings filter to permit login text strings to be filterable.
  • Introduces a wp_saml_auth_pre_authentication filter to allow authentication behavior to be adapted based on SAML response.
  • Improves error message when required SAML response attribute is missing.
  • Corrects project name in composer.json.

0.2.1 (March 22, 2017)

  • Introduces wp_saml_auth_new_user_authenticated and wp_saml_auth_existing_user_authenticated actions to permit themes / plugins to run a callback post-authentication.
  • Runs Behat test suite against latest stable SimpleSAMLphp, instead of a pinned version.

0.2.0 (March 7, 2017)

  • Introduces wp saml-auth scaffold-config, a WP-CLI command to scaffold a configuration filter to customize WP SAML Auth usage.
  • Redirects back to WordPress after SimpleSAMLPHP authentication.
  • Variety of test suite improvements.

0.1.0 (April 18, 2016)

  • Initial release.

wp-saml-auth's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-saml-auth's Issues

Url structure issue with WP MultiSite

Related to internal ticket 142154

User found the issue with simpleSAMLphp on WP Site Networks has conflicts in their naming convention for their url structure with the Site Network rewrites (the issue at hand from Pantheon's documentation concerning Shibboleth-SSO).

Does not work:
https://example.com/simplesaml/module.php/core/frontpage_welcome.php

DOES work:
https://example.com/simplesaml/module.php/core/frontpage_welcome.php/

Analysis:
The default WordPress Rewrite Rules are looking for urls that end with .php albeit to prevent odd directory access for php files directly.

User modified the code on the Simplesaml library, however that is not ideal as a workaround.

OneLogin is also not ideal, as the bindings for the different methods are strictly only HTTP-Redirect of which the authentication expects otherwise.

Possible Solution:
Is there any way that any URL ending with .php under /simplesaml/ can be excused by that catch-all rule configured on NGINX? This would resolve the multisite issue with SimpleSAMLPHP. SOME directories under simplesaml worked just fine. Anything ending in .php (even though its not a directory to a direct php file, its the way the urls are parsed by simplesamlphp's library).

Allow configuration of OneLogin library via metadata url

Heya,

Usually an IDP will offer a metadata link to their xml containing all the configuration parameters for a SAML library to use for quick configuration and incase something changes at the IDP level, it doesn't have to manually updated to the SPs.

I think it'd be a great idea to have the plugin take a metadata url and keep a copy locally that is refreshed every so often.

I'm thinking, a reference implementation could be the Moodle WP saml plugin

great library btw 👍

Can't setup auth with custom Wordpress path

Hey there, not sure if this is a bug or a configuration problem, but...

I have the plugin configured to hit my Idp's (Keycloak) IDP initiated login URL:
https://example.com/auth/realms/master/protocol/saml/clients/wordpress

That redirect works as expected, but there is a URL mismatch:

Destination in response doesn't match the current URL. Destination is "https://example.com/wp/wp-admin", current URL is "https://example.com/wp".

This sorta makes sense because the Wordpress root is https://example.com/wp, but the homepage is at https://example.com/. I can simply tell Keycloak to use https://example.com/wp as the base URL and the error goes away, but then no login actually takes place.

Any ideas?

Group to role mapping

You really ought to consider group to role mapping, and have the ability to deny access if no match was found.

Just because one have been authenticated (and got valid SAML ticket) does not mean you should automatically be granted access.

Role Mapping

This is associated with #66

Heya,
What I'm trying to figure out is, lets say SAML gives back an array of roles and I'd like to map those roles to Wordpress roles, there doesn't seem to be a way of doing that currently.

For example:

public_user => subscriber
random_user => subscriber
admin_user => administrator
upgraded_user => administrator

I see there is a wp_saml_auth_pre_authentication filter, but it only lets us change whether the signup process continues or not

I suggest adding a facility where you can add a mapping object and use that during the creation of the user. I'm thinking, here passing a function that gives us the attributes before inserting, and we can add roles

        'last_name_attribute' => 'last_name',
        /**
         * Default WordPress role to grant when provisioning new users.
         *
         * @param string
         */
        'default_role'           => get_option( 'default_role' ),
    );
    $value = isset( $defaults[ $option_name ] ) ? $defaults[ $option_name ] : $value;
    return $value;

Perhaps, adding a filter before the user gets added with the attributes and user object available?

/wp-login.php redirection does not send user to /wp-admin post-authentication

After authenticating from a direct link of /wp-login.php, I am redirected back to /wp-login.php rather than /wp-admin.

As a WP SAML Auth user, I expect the post-authentication redirect behavior to mimic that of the WordPress login whereby a user who authenticates through a direct link of /wp-login.php will be redirected to /wp-admin after a successful authentication.

Consider adding a default value of /wp-admin for the redirect_to query parameter : https://github.com/pantheon-systems/wp-saml-auth/blob/master/inc/class-wp-saml-auth.php#L161

Thanks!

Add test coverage around filter_authenticate

filter_authenticate() is our workhorse for interpreting responses from SimpleSAMLphp. We can mock SimpleSAML_Auth_Simple and write test coverage around how we handle the varying scenarios.

From #1

Release v0.1.0

Let's get it out the door!

  • Do a pass through the readme.txt to make sure everything is solid.
  • Tag the release on Github
  • Tag the release on WordPress.org

Uncaught PDOException

Hello,

I have a WordPress site hosted on Pantheon, with SimpleSAML configured. SimpleSAML is working properly when I test it directly through the web interface.

I've installed and configured this plugin, including adjusting the path to point to the recommended SimpleSAML installation path (/code/private/simplesaml-1.xx.xx). However when I click to log in using it, I get the following error:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/Store/SQL.php:54 Stack trace: #0 /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/Store/SQL.php(54): PDO->__construct('mysql:host=;por...', NULL, NULL) #1 /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/Store.php(49): SimpleSAML_Store_SQL->__construct() #2 /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/SessionHandler.php(121): SimpleSAML_Store::getInstance() #3 /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/SessionHandler.php(39): SimpleSAML_SessionHandler::createSessionHandler() #4 /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/Session.php(148): SimpleSAML_SessionHandler::getSessionHandler() #5 /s in /srv/bindings/43da63f89af94719b907b0f2e2974440/code/private/simplesamlphp-1.14.11/lib/SimpleSAML/Store/SQL.php on line 54

I also installed and enabled Native PHP Sessions for WordPress. Interestingly, when I add this line to my www/_include.php file

require_once dirname( dirname( dirname( dirname( __FILE__ ) ) ) ). '/wp-load.php';

I receive the above error trying to simply view my site.

Out of curiosity I tried setting the SimpleSAML store to phpsession, which fixed this error and allowed me to login, but attempted to redirect me back to port 18319 which I assume means some unrelated issue with trying to use phpsession.

Thank you!

Deep Links

It does't sound like this plugin supports deep links (i.e redirecting to the original requested page upon login).

We're using this plugin on a intranet site, and users must be logged in to view the site (it's under Restricted Site Access). The default behavior of the plugin is to just redirect user to home page, no matter what the url it is trying to access. By looking at the plugin code I didn't found a way to make deeps link works without modifying its code. Would you be open for a PR to add support for it? I already have this working on a fork of this plugin, basically this is what I'm doing:

$redirect_to = filter_input( INPUT_GET, 'redirect_to', FILTER_SANITIZE_URL );
			
if ( ! $redirect_to ) {
    $redirect_to = '/'
}

$this->provider->requireAuth(
	array(
	   'ReturnTo' => add_query_arg( array( 'redirect_to' => rawurlencode( $redirect_to ), $_SERVER['REQUEST_URI'] ) ),
	)
);

redirect_to is being forward to the plugin action's url if one is being set on wp-login.php.

Consider disabling user editing for SAML-provisioned users

If a user was created through the SAML IDP, we may want to consider having a feature where user editing is disabled for SAML-provisioned users.

Similarly, we may want to update the details for a SAML-provisioned user each time they log in through their IDP.

Plugin installed from WordPress repository doesn't match Github code

Hello again,

When attempting to use this plugin, after authentication we were being redirected to port 18319. Looking at the code in class-wp-saml-auth.php we noticed line 132 was

$this->provider->requireAuth();

However in the Github repository it was

$this->provider->requireAuth( array( 'ReturnTo' => $_SERVER['REQUEST_URI'] ) );

Updating the code to that version fixed our issue, so it just seems like the WordPress code repository might need that same update.

Provide UI to update and amend settings via plugin

I understand there is the cli option for configuring the plugin but I think the provision of the UI to edit the config/filters would enhance the usability of this module especially for saml admins not familiar with wordpress but required to enable the feature

Include the generated autoload files in your git

Currently the .gitignore has the following line:
/vendor/
in it, making it ignore the autoload files that are autogenerated via composer update.
But this means that the plugin cannot be installed via composer (without adding an extra step of running composer update on the plugin directory itself).
This makes automatic deployment of the plugin more complicated.
I believe the solution would be to replace it with:

vendor/*
!vendor/composer
!vendor/autoload.php

(haven't tested it though)

Log in does not work when using wp-admin URL

This issue is similar to #62.

I am using WP SAML Auth 0.3.5 and simpleSAMLphp library. I have following configuration overrides:

  if ( 'simplesamlphp_autoload' === $option ) {
    $value = ABSPATH . '/private/simplesamlphp/lib/_autoload.php';
  }
  if ( 'display_name_attribute' === $option ) {
    $value = 'displayName';
  }
  if ( 'first_name_attribute' === $option ) {
    $value = 'givenName';
  }
  if ( 'last_name_attribute' === $option ) {
    $value = 'sn';
  }
  if ( 'permit_wp_login' === $option ) {
    $value = false;
  }
  if ( 'get_user_by' === $option ) {
    $value = 'login';
  }

When permit_wp_login is turned off (false) following issue occurs.

Steps to reproduce it:

  1. Go to /wp-admin
  2. Log in using SAML
  3. You are redirected to https://<sitedomain>/wp-login.php?redirect_to=https%3A%2F%2F<sitedomain>%2Fwp-admin%2F&reauth=1 and following is shown:

screen shot 2018-01-30 at 4 51 20 pm

4. When you click `Back to GU WordPress MVP` you are visiting the home page of the website and user does not seem to be logged in.

If you remove &reauth=1 from the URL in the browser and hit enter. You are successfully logged in.

google apps setup

Is the Google Apps setup outlined here: https://pantheon.io/docs/wordpress-google-sso/ in addition to or in lieu of the default setup outlined here: https://wordpress.org/plugins/wp-saml-auth/#installation ?

I am seeing an error when trying to configure with the Google Apps setup here: https://pantheon.io/docs/wordpress-google-sso/ the error reads Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed and exactly 2 expected

My configuration is as follows:

add_filter( 'wp_saml_auth_option', function( $value, $option_name ) {
  // Use the OneLogin bundled library to connect to Google Apps
  if ( 'connection_type' === $option_name ) {
    return 'internal';
  }

  // Configuration details OneLogin uses to connect to Google Apps
  if ( 'internal_config' === $option_name ) {
    // ID for the service provider (e.g. your WordPress site)
    $value['sp']['entityId'] = 'urn:saml.sandbox.dev';
    // URL that Google Apps will redirect back to after authenticating.
    $value['sp']['assertionConsumerService']['url'] = 'https://saml.sandbox.dev';
    // ID provided for the Google Apps account.
    // 'abc123' will be something specific to your account.
    $value['idp']['entityId'] = 'https://accounts.google.com/o/saml2?idpid=t92lkw3o1';
    // URL that WordPress will redirect to for authentication.
    // 'abc123' will be a unique value specific to your account.
    $value['idp']['singleSignOnService']['url'] = 'https://accounts.google.com/o/saml2/idp?idpid=t92lkw3o1';
    // x509 certificate provided by Google Apps
    // Make sure to keep the file_get_contents because the entire certificate needs to be read into memory.
    $value['idp']['x509cert'] = file_get_contents( ABSPATH . 'wp-content/themes/renegade/private/GoogleIDPCertificate-wp-saml-auth.dev.pem' );
    return $value;
  }

  return $value;
});

Thank you for your help

Redirected to /srv/bindings/<longstring>/code/wp-login.php?action=simplesamlphp

First some background

  1. WP site Running on Pantheon
  2. SimpleSAMLphp installed in ~/code/private/simplesamlphp-x.y.z/
    with a symlink in ~/code/simplesaml/ pointing to ~/code/private/simplesamlphp-x.y.z/www
  3. WP SAML Auth plugin and WP Native PHP installed (in ~/code/wp-content/plugins/) and active
  4. Tiny custom plugin for configuring WP SAML Auth installed in ~/code/wp-content/mu-plugins/wp-saml-auth-config.php

Here's what happens

  1. Visit /wp-login.php
  2. Click the "one-click authentication" "Sign In" button
    ( goes to /wp-login.php?action=simplesamlphp)
  3. SimpleSAMLphp kicks in and sends me off to our organization's SSO system,
    and here's the problem: when SSP redirects to our IdP, the URL it includes in the RelayState parameter, the URL to come back to, is something like:
    https://sitename.pantheonsite.io//srv/bindings/<biglongstring>/code/wp-login.php?action=simplesamlphp
  4. So I log into our SSO, and get redirected back to that URL, and get a 404.

I followed the SSP code, starting with SimpleSAML_Auth_Simple::requireAuth (called from do-saml-authentication() in class-wp-saml-auth.php). Because no return URL is specified when calling requireAuth, SSP tries to figure out the return URL .. and it eventually calls \SimpleSAML\Utils\HTTP::getSelfURL() which is what returns the problematic /srv/bindings/.... URL.

My fix was to have WP SAML Auth specify a ReturnTo URL when calling requireAuth (PR coming soon). It works for me, but I'd like to try to run it through the tests too.

Way to specify which IDP to use

Kinda new to SimpleSAMLPHP but I got everything working, however when WP redirects to SimpleSAMLPHP it shows this page, even though I only have 1 SP configured and I want to force WP to use ONLY that IDP, is there a way to specify this?

simplesamlphp

From the docs it says you can specify the IDP to use in the code that calls SimpleSAMLPHP but I can't seem to figure out how to do that using this plugin

https://simplesamlphp.org/docs/stable/simplesamlphp-sp

Relevant part:

Example code:

We start off with loading a file which registers the SimpleSAMLphp classes with the autoloader.

require_once('../../lib/_autoload.php');

We select our authentication source:

$as = new SimpleSAML_Auth_Simple('default-sp');

We then require authentication:

$as->requireAuth();

And print the attributes:

$attributes = $as->getAttributes();
print_r($attributes);

Each attribute name can be used as an index into $attributes to obtain the value. Every attribute value is an array - a single-valued attribute is an array of a single element.

We can also request authentication with a specific IdP:

$as->login(array(
'saml:idp' => 'https://idp.example.org/',
));

LocalValetDriver for SimpleSAMLphp installed in /simplesaml/

For the next time I need to set this up locally:

$ cat ~/projects/wp-saml-auth/LocalValetDriver.php
<?php

class LocalValetDriver extends BasicValetDriver
{
    /**
     * Determine if the driver serves the request.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return bool
     */
    public function serves($sitePath, $siteName, $uri)
    {
        return 0 === stripos( $uri, '/simplesaml/' );
    }

    /**
     * Get the fully resolved path to the application's front controller.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return string
     */
    public function frontControllerPath($sitePath, $siteName, $uri)
    {
        $_SERVER['PHP_SELF']    = $uri;
        $_SERVER['SERVER_ADDR'] = '127.0.0.1';
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        preg_match( '#(^/simplesaml/[^\.]+\.php)(.+)#', $uri, $matches );
        $_SERVER['PATH_INFO'] = $matches[2];
        return $sitePath . $matches[1];
    }

}

Only applies for URIs with /simplesaml/; otherwise falls back to WordPressValetDriver

Add to Packagist

Can you add this repo to Packagist so we can use the version here rather than wp.org to use features like 8c4641b

Thanks, so much

Documentation request — settings arrays

Both the bundled OneLogin SAML library and this plugin require an array of settings. There's some overlap between these two settings arrays — it looks like this plugin's $defaults['internal_config'] array that you set in your WP filter function matches up with the OneLogin $settings array here.

Is there a recommendation/best practice for how to set these up in order to only define your internal config in one place?

Without the OneLogin settings file in place, we hit a fatal error from wp-content/plugins/wp-saml-auth/vendor/onelogin/php-saml/endpoints/metadata.php when attempting to view published metadata from that endpoint.

Thanks!

Error after authentication

I am running into an issue after clicking the one-click authentication, I am redirected back to my site /wp-login.php path but with a 502 error and I am not logged in.

In SAML Chrome panel I see:

<saml2:AttributeStatement>
            <saml2:Attribute Name="first_name">
                <saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:anyType">Firstname</saml2:AttributeValue>
            </saml2:Attribute>
            <saml2:Attribute Name="last_name">
                <saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:anyType">Lastname</saml2:AttributeValue>
            </saml2:Attribute>
            <saml2:Attribute Name="user_login">
                <saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:anyType">[email protected]</saml2:AttributeValue>
            </saml2:Attribute>
            <saml2:Attribute Name="user_email">
                <saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:anyType">[email protected]</saml2:AttributeValue>
            </saml2:Attribute>
        </saml2:AttributeStatement>
        <saml2:AuthnStatement AuthnInstant="2019-05-12T13:17:00.000Z"
            SessionIndex=“_839f029qhd92h0j0j9hd83hd9”>
            <saml2:AuthnContext>
                <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml2:AuthnContextClassRef>
            </saml2:AuthnContext>
        </saml2:AuthnStatement>

Make the plugin installable without the need for code changes in the theme

For the "internal" method, currently to install the plugin you need to do code changes (to pass the required data).
This presents various problems:

  • You cannot deploy using publicly open repositories (because then you would expose the entityID, signonURL etc to the public).
  • You cannot deploy multipe environments with the same code

Solution would be to have that data pass from the administration (settings of the plugin).

IdP-First authentication?

Does this plugin support IdP-First authentication?

If so, what would the Assertion Consumer Service URL be that the IdP would post login requests to?

Updates made to redirect logic since 0.3.6 has broken redirection after authentication

WordPress version: 4.9.4
wp-saml-auth version: 0.3.7
PHP version: 7.0

I am using the wp-saml-auth plugin in order to protect content on my site from non-authenticated users.

After updating the plugin to version 0.3.7 I am having issues with the redirection after authenticating:

  • A user is prompted to login to view content on a page. This is the structure of the link I use to send the user to the login page: /wp-login.php?redirect_to=https://some-example-redirect-url
  • When on the login page a user can click the "Sign In" button, and the user can authenticate with the IdP.
  • Once authenticated, however, the user is sent back to the login page (/wp-login.php?redirect_to=https://some-example-redirect-url) . I expect the user to be sent to the redirect url (https://some-example-redirect-url)
  • If the user clicks the "Sign In" button on the login page again, it is only then that the user will be redirected to the page from where they were originally prompted to log in (i.e. the redirect_to query var value).

I noticed this issue is resolved if I fallback to version 0.3.6 of the wp-saml-auth plugin.

Customising Login

I've installed the plugin and its detected my simplesaml setup. My question is whether its possible to customise the login details to change "Use one-click authentication" to something else?

permit_wp_login not works

Hi guys,
When I change "permit_wp_login" => false, I have redirected to my idp login page, have success login but after them I cant login to wp-admin, all time I redirected to
"wp-login.php?redirect_to=https%3A%2F%2Fblog_name%2Fwp-admin%2F&reauth=1"
When I set permit_wp_login => true and iniciate saml login by click on button - all works fine...can you please help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.