Zend Expressive Authentication with doctrine

Greetings.

i am trying to create a login page with zend auth. Therefore iam reading the tutorial on: https://samsonasik.wordpress.com/2018/01/12/create-login-functionality-in-expressive-3/

<?php
// config/autoload/dependencies.global.php
return [

'dependencies' => [
    'aliases' => [
        // ...
        Zend\Expressive\Authentication\UserRepositoryInterface::class =>
            Zend\Expressive\Authentication\UserRepository\PdoDatabase::class
    ],

    'factories' => [
        // ...
        Zend\Expressive\Authentication\AuthenticationInterface::class =>
            Zend\Expressive\Authentication\Session\PhpSessionFactory::class,
    ],
    // ...
],

];

In this example the “Userrepository” is mapped to a PDODatabase. My Problem is that iam using doctrine, so i do not have a PDODatabase config.

How do i use a doctrine User Entity/Repository and map it to the “Userrepository”. I would appreciate any help/examples.

Hi. The zendframework/zend-expressive-authentication package comes with a basic PDO implementation for db access. Since you’re using Doctrine, you’ll need to write your own. On the most basic level, your Doctrine user entity will need to implement the Zend\Expressive\Authentication\UserInterface and your Doctrine user repository will need to implement Zend\Expressive\Authentication\UserRepositoryInterface. You’ll then alias those in your config to your user entity and user repository respectively.

1 Like

Thank you. i got it working now :slight_smile:

1 Like