Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save jeremykendall/170c095c419a60bc0736 to your computer and use it in GitHub Desktop.

Select an option

Save jeremykendall/170c095c419a60bc0736 to your computer and use it in GitHub Desktop.
DoctrineModule stand-alone auth configuration (see https://github.com/doctrine/DoctrineModule)
<?php
// ... snip ...
use DoctrineModule\Authentication\Adapter\ObjectRepository as AuthenticationAdapter;
use DoctrineModule\Authentication\Storage\ObjectRepository as AuthenticationStorage;
use DoctrineModule\Options\Authentication as AuthenticationOptions;
use JeremyKendall\Slim\Auth\Bootstrap;
use Zend\Authentication\Storage\Session as SessionStorage;
// ... snip ...
// Implements PasswordValidator::isValid() from
// https://github.com/jeremykendall/password-validator
// Will be passed to DoctrineModule\Options\Authentication::setCredentialCallable
$credentialCallable = function (User $user, $passwordGiven) use ($passwordValidator) {
$validationResult = $passwordValidator->isValid(
$passwordGiven,
$user->getPasswordHash()
);
return $validationResult->isValid();
};
$authenticationOptions = new AuthenticationOptions();
$authenticationOptions->setObjectManager($em);
// User::getClassName() mimics AdminEntity::getClassName() from
// https://gist.github.com/Ocramius/1357662#file-session-php-L45
$authenticationOptions->setIdentityClass(User::getClassName());
$authenticationOptions->setIdentityProperty('emailCanonical');
$authenticationOptions->setCredentialProperty('passwordHash');
$authenticationOptions->setCredentialCallable($credentialCallable);
$authenticationOptions->setStorage(new SessionStorage());
$adapter = new AuthenticationAdapter($authenticationOptions);
$storage = new AuthenticationStorage($authenticationOptions);
// Bootstrap is the auth setup helper from
//https://github.com/jeremykendall/slim-auth
$authBootstrap = new Bootstrap($app, $adapter, $di->get('acl'));
$authBootstrap->setStorage($storage);
$authBootstrap->bootstrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment