How to setup multiple authentication adapters with fallback

1k Views Asked by At

I am trying to setup ZfcUser to authenticate with a fallback to LDAP. My zfcuser.global.php contains:

'auth_adapters' => array( 
    100 => 'ZfcUser\Authentication\Adapter\Db', 
    99 => 'ZfcUser\Authentication\Adapter\Ldap', 
),

I have created an Ldap.php as an AbstractAdapter with the following setup. I have eliminated function code for brevity:

namespace ZfcUser\Authentication\Adapter;

use DateTime;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\Session\Container as SessionContainer;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent;
use ZfcUser\Mapper\User as UserMapperInterface;
use ZfcUser\Options\AuthenticationOptionsInterface;


class Ldap extends AbstractAdapter implements ServiceManagerAwareInterface
{
    protected $mapper;
    protected $serviceManager;
    protected $options;

    public function authenticate(AuthEvent $e)
    {
        ...
    }

    public function getMapper()
    {
        ...
    }

    public function setMapper(UserMapperInterface $mapper)
    {
        ...
    }

    public function getServiceManager()
    {
        return $this->serviceManager;
    }

    public function setServiceManager(ServiceManager $serviceManager)
    {
        $this->serviceManager = $serviceManager;
    }

    public function setOptions(AuthenticationOptionsInterface $options)
    {
        $this->options = $options;
    }

    public function getOptions()
    {
        ...
    }  

}

I have also included it as invokable in the Module.php file:

public function getServiceConfig()
{
    return array(
        'invokables' => array(
            'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db',
            'ZfcUser\Authentication\Adapter\Ldap' => 'ZfcUser\Authentication\Adapter\Ldap',
            ...
        ),
        ...
 }

If I flip the priority values it changes who can log in. Whichever adapter is executed first allows logins but the other adapter never gets used. Anyone know how to make ZfcUser fall back to the next adapter if the first one fails?

1

There are 1 best solutions below

0
On

Issue fixed here https://github.com/SocalNick/ScnSocialAuth/issues/123

For me I just i followed matwright(github) response (See https://github.com/matwright/ScnSocialAuth) so I replace two files :

  1. socalnick/src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php by ScnSocialAuthProvider.php
  2. socalnick/src/ScnSocialAuth/Controller/UserController.php by UserController.php

And in zfcuser.global.php :

'auth_adapters' => array( 100 => 'ZfcUser\Authentication\Adapter\Db', ),

Hope this help...