Index: src/webapp/apigility/module/Application/src/Authentication/SessionAdapter.php
===================================================================
--- src/webapp/apigility/module/Application/src/Authentication/SessionAdapter.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
+++ src/webapp/apigility/module/Application/src/Authentication/SessionAdapter.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
@@ -0,0 +1,59 @@
+<?php
+// From https://apigility.org/documentation/auth/user-differentiation
+
+namespace Application\Authentication;
+
+use ZF\MvcAuth\Authentication\AdapterInterface;
+use Zend\Http\Request;
+use Zend\Http\Response;
+use ZF\MvcAuth\Identity\IdentityInterface;
+use ZF\MvcAuth\MvcAuthEvent;
+use Zend\Session\Container;
+use Application\Identity;
+
+final class SessionAdapter implements AdapterInterface
+{
+    public function provides()
+    {
+        return [
+            'session',
+        ];
+    }
+
+    public function matches($type)
+    {
+        return $type == 'session';
+    }
+
+    public function getTypeFromRequest(Request $request)
+    {
+        return false;
+    }
+
+    public function preAuth(Request $request, Response $response)
+    {
+    }
+
+    public function authenticate(Request $request, Response $response, MvcAuthEvent $mvcAuthEvent)
+    {
+        $session = new Container('webauth');
+
+        if ($session->auth) {
+            $userIdentity = new Identity\UserIdentity($session->auth);
+            $userIdentity->setName('user');
+
+            return $userIdentity;
+        }
+
+        // Force login for all other routes
+        $mvcAuthEvent->stopPropagation();
+        $session->redirect = $request->getUriString();
+        $response->getHeaders()->addHeaderLine('Location', '/login');
+        $response->setStatusCode(302);
+        $response->sendHeaders();
+
+        return $response;
+    }
+}
+
+?>
Index: src/webapp/apigility/module/Application/src/Authorization/AuthorizationListener.php
===================================================================
--- src/webapp/apigility/module/Application/src/Authorization/AuthorizationListener.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
+++ src/webapp/apigility/module/Application/src/Authorization/AuthorizationListener.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
@@ -0,0 +1,27 @@
+<?php
+// From https://apigility.org/documentation/auth/user-differentiation
+
+namespace Application\Authorization;
+
+use Application\Controller\IndexController;
+use ZF\MvcAuth\MvcAuthEvent;
+use ZF\OAuth2\Controller\Auth;
+
+final class AuthorizationListener
+{
+    public function __invoke(MvcAuthEvent $mvcAuthEvent)
+    {
+        $authorization = $mvcAuthEvent->getAuthorizationService();
+
+        // Deny from all
+        $authorization->deny();
+
+        $authorization->addResource(IndexController::class . '::index');
+        $authorization->allow('guest', IndexController::class . '::index');
+
+        $authorization->addResource(Auth::class . '::authorize');
+        $authorization->allow('user', Auth::class . '::authorize');
+    }
+}
+
+?>
Index: src/webapp/apigility/module/Application/src/Identity/UserIdentity.php
===================================================================
--- src/webapp/apigility/module/Application/src/Identity/UserIdentity.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
+++ src/webapp/apigility/module/Application/src/Identity/UserIdentity.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
@@ -0,0 +1,46 @@
+<?php
+// From https://apigility.org/documentation/auth/user-differentiation
+
+namespace Application\Identity;
+
+use ZF\MvcAuth\Identity\IdentityInterface;
+use Zend\Permissions\Rbac\AbstractRole as AbstractRbacRole;
+
+final class UserIdentity extends AbstractRbacRole implements IdentityInterface
+{
+    private $user;
+    private $name;
+
+    public function __construct(array $user)
+    {
+        $this->user = $user;
+    }
+
+    public function getAuthenticationIdentity()
+    {
+        return $this->user;
+    }
+
+    public function getId()
+    {
+        return $this->user['id'];
+    }
+
+    public function getUser()
+    {
+        return $this->getAuthenticationIdentity();
+    }
+
+    public function getRoleId()
+    {
+        return $this->name;
+    }
+
+    // Alias for roleId
+    public function setName($name)
+    {
+        $this->name = $name;
+    }
+}
+
+?>
Index: src/webapp/apigility/module/Application/src/Module.php
===================================================================
--- src/webapp/apigility/module/Application/src/Module.php	(revision 74c3571b330568daeee1f4562299f3daae280ddf)
+++ src/webapp/apigility/module/Application/src/Module.php	(revision cb39a771d37f2a3a7ff4dceaa71ea42cca3552d7)
@@ -3,7 +3,13 @@
  * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
  * @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com)
+ *
+ * partly copied from https://apigility.org/documentation/auth/user-differentiation
  */
 
 namespace Application;
+
+use ZF\MvcAuth\Authentication\DefaultAuthenticationListener;
+use Zend\EventManager\EventInterface;
+use ZF\MvcAuth\MvcAuthEvent;
 
 class Module
@@ -13,3 +19,21 @@
         return include __DIR__ . '/../config/module.config.php';
     }
+    
+    public function onBootstrap(EventInterface $e)
+    {
+        $app       = $e->getApplication();
+        $container = $app->getServiceManager();
+
+        // Add Authentication Adapter for session
+        $defaultAuthenticationListener = $container->get(DefaultAuthenticationListener::class);
+        $defaultAuthenticationListener->attach(new Authentication\SessionAdapter());
+        
+        // Add Authorization
+		$eventManager = $app->getEventManager();
+		$eventManager->attach(
+			MvcAuthEvent::EVENT_AUTHORIZATION,
+			new Authorization\AuthorizationListener(),
+			100
+		);
+    }
 }
