2

I work on implementing single sign on with joomla and simplesamlphp.

I try to use the simpleamlphp api in the context of a joomla plugin in the onAfterInitialise event.

To that end, the plugin in the onAfterInitialise event detects if there are in the parameters sent by the HTTP request one with name simplesamlphp and with valuesso, if it is true I start the object \SimpleSAML\Auth\Simple and start the authentication process by calling the requireAuth() method. This shows the simpleamlphp authentication form and by providing valid credentials redirects me to the site that initiated the authentication process, here I try to access the attributes of the authenticated user.

My problem is that I cannot access the attributes of the authenticated user in simplesamlphp because I cannot access the original instance of the \SimpleSAML\ Auth\Simple object

I am now trying to save the object in a session variable but I am getting the class error __PHP_Incomplete_Class

This is the code I'm trying

<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

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

class plgSystemMysamlredirect extends JPlugin
{
    public function onAfterInitialise()
    {
        $application = JFactory::getApplication();
        $session = JFactory::getSession();

        $jinput = $application->input;

        $get = (object) $jinput->get->getArray();

        if (isset($get->simplesamlphp) && $get->simplesamlphp === 'sso') {
            $auth = new SimpleSAML_Auth_Simple('default-sp');

            $session->set('auth', $auth);

            $auth->requireAuth();
        }

        $auth = $session->get('auth');

        if (!is_null($auth)) {
            if ($auth->isAuthenticated()) {
                $attributes = $auth->getAttributes();

                print_r($attributes);
            }
        }
    }
}

Update

to avoid the __PHP_Incomplete_Class error, before storing the object in session I do a cast a array and then to access it I do a cast object of the session variable. but when trying to call the isAuthenticated() method, the error returns with the message that the method does not exist

When setting

$session->set('authentication', (array) $authentication);

When getting

$authentication = (object) $session->get('authentication');

I welcome your comments and suggestions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.