public function setUp()
 {
     $storage = new PdoStorage(new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']));
     $storage->initDatabase();
     $storage->addClient(new ClientData(array('id' => 'testclient', 'name' => 'Simple Test Client', 'description' => 'Client for unit testing', 'secret' => null, 'icon' => null, 'allowed_scope' => 'read', 'disable_user_consent' => false, 'contact_email' => '*****@*****.**', 'redirect_uri' => 'http://localhost/php-oauth/unit/test.html', 'type' => 'token')));
     $storage->storeAccessToken('foo', 1111111111, 'testclient', 'fkooman', 'foo bar', 1234);
     $storage->storeAccessToken('bar', 1111111111, 'testclient', 'frko', 'a b c', 1234);
     $ioStub = $this->getMockBuilder('fkooman\\OAuth\\Server\\IO')->getMock();
     $ioStub->method('getRandomHex')->will($this->onConsecutiveCalls('11111111'));
     $ioStub->method('getTime')->willReturn(1111111111);
     $this->service = new TokenIntrospectionService($storage, $ioStub);
 }
예제 #2
0
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
use fkooman\Ini\IniReader;
use fkooman\OAuth\Server\PdoStorage;
use fkooman\OAuth\Server\TokenService;
use fkooman\Rest\Plugin\Basic\BasicAuthentication;
use fkooman\Rest\PluginRegistry;
use fkooman\Rest\ExceptionHandler;
ExceptionHandler::register();
$iniReader = IniReader::fromFile(dirname(__DIR__) . '/config/oauth.ini');
$db = new PDO($iniReader->v('PdoStorage', 'dsn'), $iniReader->v('PdoStorage', 'username', false), $iniReader->v('PdoStorage', 'password', false));
$pdoStorage = new PdoStorage($db);
$basicAuthenticationPlugin = new BasicAuthentication(function ($userId) use($pdoStorage) {
    $clientData = $pdoStorage->getClient($userId);
    return false !== $clientData ? password_hash($clientData->getSecret(), PASSWORD_DEFAULT) : false;
}, 'OAuth Server');
$service = new TokenService($pdoStorage, null, $iniReader->v('accessTokenExpiry'));
$pluginRegistry = new PluginRegistry();
$pluginRegistry->registerDefaultPlugin($basicAuthenticationPlugin);
$service->setPluginRegistry($pluginRegistry);
$service->run()->send();