/**
  * @return Authorization\Dispatcher
  */
 public function getAuthorizationDispatcher()
 {
     if (!$this->authorizationDispatcher instanceof Authorization\Dispatcher) {
         $this->authorizationDispatcher = new Authorization\Dispatcher();
         $this->authorizationDispatcher->setStateManager($this->getStateManager());
     }
     return $this->authorizationDispatcher;
 }
use InoOicClient\Http\ClientFactory;
use InoOicClient\Oic\Authorization;
use InoOicClient\Oic\Token;
use InoOicClient\Oic\UserInfo;
use InoOicClient\Client\ClientInfo;
use InoOicClient\Oic\Authorization\State\Manager;
use InoOicClient\Oic\Exception\ErrorResponseException;
use InoOicClient\Oic\Authorization\Exception\StateException;
use Zend\Http\Client;
require __DIR__ . '/../init_autoload.php';
$config = (require __DIR__ . '/config.php');
$clientInfo = new ClientInfo();
$clientInfo->fromArray($config['client_info']);
$stateManager = new Manager();
$dispatcher = new Authorization\Dispatcher();
$dispatcher->setStateManager($stateManager);
if (!isset($_GET['redirect'])) {
    $request = new Authorization\Request($clientInfo, 'code', 'openid profile email');
    $uri = $dispatcher->createAuthorizationRequestUri($request);
    _dump($uri);
    printf("<pre>%s</pre><br>", $uri);
    printf("<a href=\"%s\">Login</a>", $uri);
} else {
    try {
        $response = $dispatcher->getAuthorizationResponse();
        printf("OK<br>Code: %s<br>State: %s<br>", $response->getCode(), $response->getState());
        $tokenRequest = new Token\Request();
        $tokenRequest->fromArray(array('client_info' => $clientInfo, 'code' => $response->getCode(), 'grant_type' => 'authorization_code'));
        $httpClient = _createHttpClient();
        $tokenDispatcher = new Token\Dispatcher($httpClient);
 public function testGetAuthorizationResponseOkWithState()
 {
     $code = '123';
     $stateHash = 'abc';
     $state = $this->createStateMock();
     $dispatcher = new Dispatcher();
     $httpRequest = $this->createHttpRequestMock(array('code' => $code, 'state' => $stateHash));
     $response = $this->createResponseMock();
     $responseFactory = $this->createResponseFactoryMock($code, $response, $stateHash);
     $dispatcher->setResponseFactory($responseFactory);
     $stateManager = $this->createStateManagerMock($stateHash);
     $dispatcher->setStateManager($stateManager);
     $this->assertSame($response, $dispatcher->getAuthorizationResponse($httpRequest));
     $this->assertSame($httpRequest, $dispatcher->getLastHttpRequestFromServer());
     $this->assertSame($response, $dispatcher->getLastResponse());
 }