return $result && $result['client_secret'] == $client_secret; } } $authenticateForRole = function () { //global $conOptions; $_dsn = diyConfig::read('db.dsn'); $_username = diyConfig::read('db.username'); $_password = diyConfig::read('db.password'); $storage = new PdoStorageWithEmailVerification(array('dsn' => $_dsn, 'username' => $_username, 'password' => $_password)); //$storage = new OAuth2\Storage\Pdo(array('dsn' => $_dsn, 'username' => $_username, 'password' => $_password)); $server = new OAuth2\Server($storage); $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage), array('allow_credentials_in_request_body => true')); $cryptoStorage = new OAuth2\Storage\CryptoToken($storage); $server->addStorage($cryptoStorage, "access_token"); $cryptoResponseType = new OAuth2\ResponseType\CryptoToken($storage); $server->addResponseType($cryptoResponseType); return $server; }; $diy_storage = function () { //global $conOptions; $_dbfile = diyConfig::read('db.file'); $db = new PDO(sprintf('sqlite:%s', $_dbfile)); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; }; $diy_exception = function () { $exception = new CustomException(); return $exception; }; //========================= POST ==================================