Attach an authenticator

@param  mixed $authenticator An object that implements DispatcherAuthenticatorInterface, an ObjectIdentifier
or valid identifier string
@param  array  $config  An optional associative array of configuration options
@return $this
13946
public function addAuthenticator($authenticator, $config = array())
    {
        //Create the complete identifier if a partial identifier was passed
        if (is_string($authenticator) && strpos($authenticator, '.') === false)
        {
            $identifier = $this->getIdentifier()->toArray();

            if($identifier['type'] == 'lib') {
                $identifier['path'] = array('authenticator');
            } else {
                $identifier['path'] = array('dispatcher', 'authenticator');
            }

            $identifier['name'] = $authenticator;

            $identifier = $this->getIdentifier($identifier);
        }
        else $identifier = $this->getIdentifier($authenticator);

        if (!isset($this->__authenticators[(string)$identifier]))
        {
            if(!$authenticator instanceof DispatcherAuthenticatorInterface) {
                $authenticator = $this->getObject($identifier, $config);
            }

            if (!($authenticator instanceof DispatcherAuthenticatorInterface))
            {
                throw new \UnexpectedValueException(
                    "Authenticator $identifier does not implement DispatcherAuthenticatorInterface"
                );
            }

            //Store the filter
            $this->__authenticators[$authenticator->getScheme()] = $authenticator;

            //Enqueue the filter
            $this->__authenticator_queue->enqueue($authenticator, $authenticator->getPriority());
        }

        return $this;
    }
827330
public function setSecret(string $secret):Authenticator{

		if(!preg_match('/^['.Base32::RFC3548.']+$/', $secret)){
			throw new AuthenticatorException('Invalid secret phrase');
		}

		$this->secret = $this->base32->toString($secret);

		return $this;
	}
100882
public function authenticate(ServerRequestInterface $request, ResponseInterface $response)
    {
        if ($this->authenticators()->isEmpty()) {
            throw new RuntimeException(
                'No authenticators loaded. You need to load at least one authenticator.'
            );
        }

        $result = null;
        foreach ($this->authenticators() as $authenticator) {
            $result = $authenticator->authenticate($request, $response);
            if ($result->isValid()) {
                if (!($authenticator instanceof StatelessInterface)) {
                    $requestResponse = $this->persistIdentity($request, $response, $result->getData());
                    $request = $requestResponse['request'];
                    $response = $requestResponse['response'];
                }

                $this->_successfulAuthenticator = $authenticator;
                $this->_result = $result;

                return [
                    'result' => $result,
                    'request' => $request,
                    'response' => $response
                ];
            }

            if ($authenticator instanceof StatelessInterface) {
                $authenticator->unauthorizedChallenge($request);
            }
        }

        $this->_successfulAuthenticator = null;
        $this->_result = $result;

        return [
            'result' => $result,
            'request' => $request,
            'response' => $response
        ];
    }
986461
public function setConfig(array $config) {
        $default_account = config('imap.default');
        $default_config  = config("imap.accounts.$default_account");

        foreach ($this->valid_config_keys as $key) {
            $this->$key = isset($config[$key]) ? $config[$key] : $default_config[$key];
        }

        return $this;
    }
929460
function authenticator($authenticatorName = self::AUTHENTICATOR_DEFAULT)
    {
        if (!$this->authenticators->has($authenticatorName))
            throw new \Exception(sprintf('Authenticator (%s) Not Registered.', $authenticatorName));

        $authenticator = $this->authenticators->get($authenticatorName);
        return $authenticator;
    }
721899
public function bindAuth()
    {
        $credentials = [
            'client_id' => env('AUTH_CLIENT_ID'),
            'client_secret' => env('AUTH_CLIENT_SECRET'),
            'username' => env('AUTH_SERVICE_USERNAME'),
            'password' => env('AUTH_SERVICE_PASSWORD'),
        ];

        // Bind token authenticator with its dependencies
        $this->app->bind(Authentication\TokenAuthenticator::class, function (Application $app) use ($credentials) {
            $client = $app->make('ej:sdk:guzzle');
            $cache = $app->make(Repository::class);

            return new Authentication\TokenAuthenticator($client, $cache, $credentials);
        });

        // Bind Authenticator contract to token auth as default implementation
        $this->app->bind(Authentication\Authenticator::class, function (Application $app) use ($credentials) {
            return $app->make(Authentication\TokenAuthenticator::class);
        });
    }
384143
public function addAuthenticationFactory(AuthenticationFactoryInterface $authFactory,
                                             UserProviderInterface $userProvider)
    {
        $id = $authFactory->getId();

        $this->authFactories[$id] = array(
            'factory' => $authFactory,
            'userProvider' => $userProvider,
        );

        $this->userProviders[] = $userProvider;

        if ($this->provider) {
            $this->registerAuthenticationFactory($this->provider->getApp(), $id, $authFactory, $userProvider);
        }

        return $this;
    }
148555
public function authenticate(array $credentials)
    {

        // Dirty hack so we can use in both User->Authenticator->authenticate() and \Nette\Security\User->login() methods
        // arrays with named keys instead of anonymous arrays.
        // Eg. $userAuthenticator->authenticate(['username' => $username, 'alwaysLogin' => true]); instead of
        // $userAuthenticator->authenticate([$username, null, null, null, true]);
        if (count($credentials) == 1 && isset($credentials[0]) && is_array($credentials[0])) {
            $credentials = $credentials[0];
        }

        $user = false;
        $source = null;
        $regenerateToken = null;
        $exception = null;
        $authenticators = $this->authenticatorManager->getAuthenticators();
        /** @var AuthenticatorInterface $authenticator */
        foreach ($authenticators as $authenticator) {
            try {
                $u = $authenticator->setCredentials($credentials)->authenticate();

                $regenerateToken = $authenticator->shouldRegenerateToken();

                if ($u !== null && $u !== false) {
                    $user = $u;
                    $source = $authenticator->getSource();
                    break;
                }
            } catch (RateLimitException $e) {
                $exception = $e;
                break;
            } catch (AuthenticationException $e) {
                if ($exception === null) {
                    $exception = $e;
                }
                continue;
            }
        }

        if ($user === false && $exception !== null) {
            throw $exception;
        }
        if ($user === false) {
            throw new AuthenticationException('', UserAuthenticator::IDENTITY_NOT_FOUND);
        }
        $this->emitter->emit(new UserSignInEvent($user, $source, $regenerateToken ?? true));

        $arr = $user->toArray();
        unset($arr[self::COLUMN_PASSWORD_HASH]);

        $groups = [];
        if ($user['role'] === UsersRepository::ROLE_ADMIN) {
            $userGroups = $user->related('admin_user_groups');
            foreach ($userGroups as $userGroup) {
                $groups[] = $userGroup->admin_group->name;
            }
        }

        return new Identity($user['id'], $groups, $arr);
    }
194984
protected function setCredentials(array $config = [])
    {
        if (!isset($config['username']) || !isset($config['password']) || !isset($config['customer_number'])) {
            $message = 'A username, password and customer number are required for authenticated to the Canada Post API.';
            throw new \InvalidArgumentException($message);
        }

        $this->username = $config['username'];
        $this->password = $config['password'];
        $this->customerNumber = $config['customer_number'];
        $this->contractId = isset($config['contract_id']) ? $config['contract_id'] : null;
    }
161624
public function addValidator($validator)
    {
        if (!($validator instanceof ValidatorInterface) && !is_callable($validator)) {
            $validator = ValidatorHelper::create($validator);
        }

        $this->validator->addValidator($validator);

        return $this;
    }
181056
public function setCredentials(array $credentials) : AuthenticatorInterface
    {
        if (array_key_exists('source', $credentials) && preg_match('/^api*/', $credentials['source'])) {
            $this->api = true;
            $this->source = $credentials['source'];
        }

        return $this;
    }
461973
private function getAuthenticator(): IAuthenticator
	{
		$ns = $this->userStorage->getNamespace();
		if (isset($this->mapper[$ns])) {
			$ns = $this->mapper[$ns];
		}
		if (!isset($this->authenticators[$ns])) {
			throw new UnexpectedValueException("Namespace '$ns' is not registered");
		}
		return $this->authenticators[$ns];
	}
833003
public function End($Authenticator = NULL) {
      if ($Authenticator == NULL)
         $Authenticator = Gdn::Authenticator();

      $Authenticator->AuthenticateWith()->DeAuthenticate();
      $this->SetCookie('-Vv', NULL, -3600);
      
      $this->UserID = 0;
      $this->User = FALSE;
      $this->_Attributes = array();
      $this->_Permissions = array();
      $this->_Preferences = array();
      $this->_TransientKey = FALSE;
   }
1281541
private function authenticateWithPassword()
    {
        if ($this->credentials->havePassword()) {
            $authCommand = new Auth();
            $authCommand->setArguments([$this->credentials->getPassword()]);
            $authResponse = $this->connection->execute($authCommand);
            $response = $authCommand->parse($authResponse);
            if ($response !== self::AUTH_SUCCESS_MESSAGE) {
                throw new AuthenticationException();
            }
        }
    }
480949
protected function createUsersBroker(array $config)
    {
        return new VerificationBroker(
            $this->createTokenRepository($this->app['config']['verification.repositories.'.$config['repository']]),
            $this->app['auth']->createUserProvider($config['provider']),
            $this->app['mailer'],
            $config['email']
        );
    }
182882
public static function setConfig($identifier, array $config)
    {
        $objIdentifier = self::getIdentifier($identifier);
        $strIdentifier = (string) $objIdentifier;

        if (isset(self::$_configs[$strIdentifier])) {
            self::$_configs[$strIdentifier] = self::$_configs[$strIdentifier]->append($config);
        } else {
            self::$_configs[$strIdentifier] = new AnConfig($config);
        }
    }
1364674
public function loadConfiguration(array $config = [])
    {
        if (isset($config['login'])) {
            $this->setLogin($config['login']);
        }
        if (isset($config['password'])) {
            $this->setPassword($config['password']);
        }
        if (isset($config['dsn'])) {
            $this->setDSN($config['dsn']);
        }
        return $this;
    }