public function testCreateAuthorizationRequestUriWithState()
 {
     $uri = 'https://oic.server.org/authorize?foo=bar';
     $hash = 'a0a0a0a0a';
     $request = $this->createAuthorizationRequest();
     $request->expects($this->once())->method('setState')->with($hash);
     $uriGenerator = $this->createUriGeneratorMock($request, $uri);
     $dispatcher = new Dispatcher($uriGenerator);
     $state = $this->createStateMock($hash);
     $stateManager = $this->createStateManagerMock();
     $stateManager->expects($this->once())->method('initState')->will($this->returnValue($state));
     $dispatcher->setStateManager($stateManager);
     $this->assertSame($uri, $dispatcher->createAuthorizationRequestUri($request));
     $this->assertSame($request, $dispatcher->getLastRequest());
 }
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);
        try {
            $tokenResponse = $tokenDispatcher->sendTokenRequest($tokenRequest);
            _dump($tokenResponse);
            printf("Access token: %s<br>", $tokenResponse->getAccessToken());