General > Support

Modify Mibew to use SAML

<< < (2/2)

mscherst:
I'm hitting a block here, and it's the same basic issue for two things I need to accomplish.

First, as I stated above, I need to generate a url inside of the plugin, using something like:


--- Code: ---$this->getRouter()->generateUrl('home');
--- End code ---

Second, after my third-party authentication service has returned a successful response, I need to do something similar to what's happening in Mibew\Controller\LoginController:


--- Code: ---$this->getAuthenticationManager()->loginOperator($operator, $remember);
--- End code ---

While I have some experience with scripting in php, I'm new to app development, and Symfony in particular.  That last line of code responds with an error:


--- Quote ---PHP Fatal error:  Uncaught Error: Call to a member function loginOperator() on null
--- End quote ---

I see in index.php, an application object is created after first creating a router:


--- Code: ---$application = new Application($router, new AuthenticationManager());
--- End code ---

Is there a way, from inside a plugin (either Plugin.php or inside a controller) to access this Application object?  A brief example would be very helpful.

faf:
To begin with, I'd implement third-party authentication that way:

In run():


--- Code: ---$dispatcher = EventDispatcher::getInstance();
$dispatcher->attachListener(Events::OPERATOR_AUTHENTICATE, $this, 'checkAuth');

--- End code ---

And your checkAuth method should looks somehow like that:


--- Code: ---public function checkAuth(&$args)
    {
        $request = $args['request'];

        $login = $request->request->get('login');
        $password = $request->request->get('password');
        $operator = operator_by_login($login);

        if ((!$operator || ($operator['vcpassword'] === 'auth_by_remote_service')) && $login && $password) {

               // dummy part
               // do something and get auth result
               // ...
               $result = true;
               // ...
               // end of dummy part

               if (!$result) {
                       return;
               }
           
                if (!$operator) {
                       $operator = create_operator($login, '', '', '', '', '', '');
                       $operator = operator_by_login($login);
                       $operator['vcpassword'] = 'auth_by_remote_service';
                       update_operator($operator);
                }
                else {
                       update_operator($operator);
                }
           
                $args['operator'] = $operator;
        }

--- End code ---

Of course it's just a quick'n'dirty concept to illustrate the basic idea.

And if you need an URI related to Mibew, why won't you make use of the very same request object? $request->getUri() will do the job. You'll be able to redirect an operator to the very same page he originally requested.

Navigation

[0] Message Index

[*] Previous page

Go to full version