<?php

// This is OpenIDConnect Sample Protected Resource
// process Request
require_once './lib/DataHandler.php';
// process request
$headers = apache_request_headers();
$request = new Akita_OpenIDConnect_Server_Request('resource', $_SERVER, $_GET, $headers);
$dataHandler = new Akita_OpenIDConnect_Server_Sample_DataHandler($request);
$resource = new Akita_OpenIDConnect_Server_UserInfo();
try {
    $authInfo = $resource->processRequest($dataHandler);
} catch (Akita_OAuth2_Server_Error $error) {
    // error handling
    header('HTTP/1.1 ' . $error->getOAuth2Code());
    header('Content-Type: application/json;charset=UTF-8');
    header('Cache-Control: no-store');
    header('Pragma: no-cache');
    $res = array();
    $res['error'] = $error->getOAuth2Error();
    $desc = $error->getOAuth2ErrorDescription();
    if (!empty($desc)) {
        $res['error_description'] = $desc;
    }
    echo Akita_OpenIDConnect_Util_Json::encode($res);
    exit;
}
// build response
$res = array();
foreach ($authInfo->userInfoClaims as $claim_name) {
    $res[$claim_name] = $claim_name . "_value";
 public function test_processRequest_invalid_schema()
 {
     $server = array();
     $params = array('schema' => 'invalid', 'access_token' => 'valid_access_token');
     $request = new Akita_OAuth2_Server_Request('authorization', $server, $params);
     $accessToken = new Akita_OAuth2_Model_AccessToken();
     $accessToken->token = 'valid_access_token';
     $dataHandler = new DataHandler_UserInfo_Test($request, null, $accessToken);
     $protectedResource = new Akita_OpenIDConnect_Server_UserInfo();
     try {
         unset($accessToken);
         $authInfo = $protectedResource->processRequest($dataHandler);
     } catch (Akita_OAuth2_Server_Error $error) {
         $this->assertEquals('400', $error->getOAuth2Code(), $error->getMessage());
         $this->assertEquals('invalid_schema', $error->getOAuth2Error(), $error->getMessage());
         $this->assertEmpty($error->getOAuth2ErrorDescription(), $error->getMessage());
     }
 }