SAML-Toolkits / wordpress-saml

OneLogin SAML plugin for Wordpress
MIT License
65 stars 73 forks source link

Add filters/actions #28

Open donfal71 opened 8 years ago

donfal71 commented 8 years ago

Hi,

In order to allow more customization and to better fit standard Wordpress plugin development, It could be great to add some filters/actions within the plugin.

In my personal use, I needed to add filters before sending SAML request to configure the RelayState (in my case the relaystate is dynamic to handle redirection) and I add actions in the case of an authenticated user who can't access the app instead of getting a basic error.

If you think this issue is relevant, I can do the job.

Thanks for your work,

Sommy

pitbulk commented 8 years ago

I think it makes sense, send the PR and let me review it.

nicoladj77 commented 7 years ago

@pitbulk at what level would it make more sense for you to filter?

I would add

$parameters = apply_filters( 'onelogin_saml_sso_login_parameters', $parameters );

to method login of the Saml2/Auth.php class, although, if that's a library, maybe it doesn't make sense to change there.

Another possibility would be to add the support for a get parameter like "redirect_to". Something like

function saml_sso() {
    if ( is_user_logged_in() ) {
        wp_safe_redirect( admin_url() ) ;
        exit();
    }

    if ( ! Helpers\is_sso_login_allowed() ) {
        return false;
    }

    $auth = initialize_saml();
    if ( isset( $_SERVER['REQUEST_URI'] ) && ! isset( $_GET['saml_sso'] ) ) {
        $auth->login( $_SERVER['REQUEST_URI'] );
    } else {
        $redirect_to = '';
        if ( isset( $_GET['redirect_to'] ) && $_GET['redirect_to'] ) {
            $redirect_to = $_GET['redirect_to'];
        }
        $auth->login( $redirect_to );
    }
    exit();

}