How to implement OAuth2 without Apigility

authentication
rest
zend-mvc

#1

I’m trying to implement an OAuth2-Server on zend framework 3 to manage authentication and to protect my API. i tried this module ZF-OAuth2 but i can’t find how to make it work.


#2

What exactly have you tried with regards to zf-oauth2? Have you followed this installation instructions in the README? If so, what errors did you run into?


#3

i have tried this module for user authentication ZF-OAuth2-doctrine .
the problem now is that when i pass parameters i get this response

Stack trace:
1. Whoops\Exception\ErrorException->() /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ArrayType.php:58
2. unserialize() /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ArrayType.php:58
3. Doctrine\DBAL\Types\ArrayType->convertToPHPValue() /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:303
4. Doctrine\ORM\Internal\Hydration\AbstractHydrator->gatherRowData() /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:333
5. Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData() /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:165
6. Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData() /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:150
7. Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:720
8. Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load() /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:196
9. Doctrine\ORM\EntityRepository->findOneBy() /var/www/vendor/api-skeletons/zf-oauth2-doctrine/src/Adapter/DoctrineAdapter.php:259
10. ZF\OAuth2\Doctrine\Adapter\DoctrineAdapter->isPublicClient() /var/www/vendor/bshaffer/oauth2-server-php/src/OAuth2/ClientAssertionType/HttpBasic.php:57
11. OAuth2\ClientAssertionType\HttpBasic->validateRequest() /var/www/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/TokenController.php:135
12. OAuth2\Controller\TokenController->grantAccessToken() /var/www/vendor/bshaffer/oauth2-server-php/src/OAuth2/Controller/TokenController.php:68
13. OAuth2\Controller\TokenController->handleTokenRequest() /var/www/vendor/bshaffer/oauth2-server-php/src/OAuth2/Server.php:301
14. OAuth2\Server->handleTokenRequest() /var/www/vendor/zfcampus/zf-oauth2/src/Controller/AuthController.php:107
15. ZF\OAuth2\Controller\AuthController->tokenAction() /var/www/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php:78
16. Zend\Mvc\Controller\AbstractActionController->onDispatch() /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php:322
17. Zend\EventManager\EventManager->triggerListeners() /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php:179
18. Zend\EventManager\EventManager->triggerEventUntil() /var/www/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php:106
19. Zend\Mvc\Controller\AbstractController->dispatch() /var/www/vendor/zendframework/zend-mvc/src/DispatchListener.php:138
20. Zend\Mvc\DispatchListener->onDispatch() /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php:322
21. Zend\EventManager\EventManager->triggerListeners() /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php:179
22. Zend\EventManager\EventManager->triggerEventUntil() /var/www/vendor/zendframework/zend-mvc/src/Application.php:332
23. Zend\Mvc\Application->run() /var/www/public/index.php:40

i use ajax for authentication
and this is my code

$.ajax({
    method: "POST",
    url: base_url + '/oauth',
    data: {
        username : $('#login-username').val(),
        password : $('#login-password').val(),
        rememberMe : rememberMe,
        grant_type : 'password',
        client_id: 'public'
    },
})