mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
Fix CS
This commit is contained in:
@@ -21,278 +21,270 @@
|
||||
*/
|
||||
class API_OAuth2_Account
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
*
|
||||
* @var User_Adapter
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var User_Adapter
|
||||
*/
|
||||
protected $user;
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected $application;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $application_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $application_id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_version;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $revoked;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $revoked;
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $created_on;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $created_on;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param int $account_id
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function __construct(appbox &$appbox, $account_id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = (int) $account_id;
|
||||
$sql = 'SELECT api_account_id, usr_id, api_version, revoked
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param int $account_id
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function __construct(appbox &$appbox, $account_id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = (int) $account_id;
|
||||
$sql = 'SELECT api_account_id, usr_id, api_version, revoked
|
||||
, application_id, created
|
||||
FROM api_accounts
|
||||
WHERE api_account_id = :api_account_id';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':api_account_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':api_account_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->application_id = (int) $row['application_id'];
|
||||
$this->user = User_Adapter::getInstance($row['usr_id'], $this->appbox);
|
||||
$this->application_id = (int) $row['application_id'];
|
||||
$this->user = User_Adapter::getInstance($row['usr_id'], $this->appbox);
|
||||
|
||||
$this->api_version = $row['api_version'];
|
||||
$this->revoked = !!$row['revoked'];
|
||||
$this->created_on = new DateTime($row['created']);
|
||||
$this->api_version = $row['api_version'];
|
||||
$this->revoked = ! ! $row['revoked'];
|
||||
$this->created_on = new DateTime($row['created']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function get_user()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function get_user()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_api_version()
|
||||
{
|
||||
return $this->api_version;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_api_version()
|
||||
{
|
||||
return $this->api_version;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_revoked()
|
||||
{
|
||||
return $this->revoked;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_revoked()
|
||||
{
|
||||
return $this->revoked;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function set_revoked($boolean)
|
||||
{
|
||||
$this->revoked = !!$boolean;
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function set_revoked($boolean)
|
||||
{
|
||||
$this->revoked = ! ! $boolean;
|
||||
|
||||
$sql = 'UPDATE api_accounts SET revoked = :revoked
|
||||
$sql = 'UPDATE api_accounts SET revoked = :revoked
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$params = array(
|
||||
':revoked' => ($boolean ? '1' : '0')
|
||||
, 'account_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':revoked' => ($boolean ? '1' : '0')
|
||||
, 'account_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_created_on()
|
||||
{
|
||||
return $this->created_on;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function get_token()
|
||||
{
|
||||
if (!$this->token)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->token = new API_OAuth2_Token($this->appbox, $this);
|
||||
}
|
||||
catch (Exception_NotFound $e)
|
||||
{
|
||||
$this->token = API_OAuth2_Token::create($this->appbox, $this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Application
|
||||
*/
|
||||
public function get_application()
|
||||
{
|
||||
if (!$this->application)
|
||||
$this->application = new API_OAuth2_Application($this->appbox, $this->application_id);
|
||||
|
||||
return $this->application;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->get_token()->delete();
|
||||
|
||||
foreach(API_OAuth2_AuthCode::load_codes_by_account($this->appbox, $this) as $code)
|
||||
/**
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_created_on()
|
||||
{
|
||||
$code->delete();
|
||||
}
|
||||
foreach(API_OAuth2_RefreshToken::load_by_account($this->appbox, $this) as $token)
|
||||
{
|
||||
$token->delete();
|
||||
return $this->created_on;
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM api_accounts WHERE api_account_id = :account_id';
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function get_token()
|
||||
{
|
||||
if ( ! $this->token) {
|
||||
try {
|
||||
$this->token = new API_OAuth2_Token($this->appbox, $this);
|
||||
} catch (Exception_NotFound $e) {
|
||||
$this->token = API_OAuth2_Token::create($this->appbox, $this);
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array('account_id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Application
|
||||
*/
|
||||
public function get_application()
|
||||
{
|
||||
if ( ! $this->application)
|
||||
$this->application = new API_OAuth2_Application($this->appbox, $this->application_id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param User_Adapter $user
|
||||
* @param API_OAuth2_Application $application
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function create(appbox &$appbox, User_Adapter $user, API_OAuth2_Application $application)
|
||||
{
|
||||
$sql = 'INSERT INTO api_accounts
|
||||
return $this->application;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->get_token()->delete();
|
||||
|
||||
foreach (API_OAuth2_AuthCode::load_codes_by_account($this->appbox, $this) as $code) {
|
||||
$code->delete();
|
||||
}
|
||||
foreach (API_OAuth2_RefreshToken::load_by_account($this->appbox, $this) as $token) {
|
||||
$token->delete();
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM api_accounts WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array('account_id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param User_Adapter $user
|
||||
* @param API_OAuth2_Application $application
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function create(appbox &$appbox, User_Adapter $user, API_OAuth2_Application $application)
|
||||
{
|
||||
$sql = 'INSERT INTO api_accounts
|
||||
(api_account_id, usr_id, revoked, api_version, application_id, created)
|
||||
VALUES (null, :usr_id, :revoked, :api_version, :application_id, :created)';
|
||||
|
||||
$datetime = new Datetime();
|
||||
$params = array(
|
||||
':usr_id' => $user->get_id()
|
||||
, ':application_id' => $application->get_id()
|
||||
, ':api_version' => API_OAuth2_Adapter::API_VERSION
|
||||
, ':revoked' => 0
|
||||
, ':created' => $datetime->format("Y-m-d H:i:s")
|
||||
);
|
||||
$datetime = new Datetime();
|
||||
$params = array(
|
||||
':usr_id' => $user->get_id()
|
||||
, ':application_id' => $application->get_id()
|
||||
, ':api_version' => API_OAuth2_Adapter::API_VERSION
|
||||
, ':revoked' => 0
|
||||
, ':created' => $datetime->format("Y-m-d H:i:s")
|
||||
);
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$account_id = $appbox->get_connection()->lastInsertId();
|
||||
$account_id = $appbox->get_connection()->lastInsertId();
|
||||
|
||||
return new self($appbox, $account_id);
|
||||
}
|
||||
return new self($appbox, $account_id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Application $application
|
||||
* @param User_Adapter $user
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function load_with_user(appbox &$appbox, API_OAuth2_Application $application, User_Adapter $user)
|
||||
{
|
||||
$sql = 'SELECT api_account_id FROM api_accounts
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Application $application
|
||||
* @param User_Adapter $user
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function load_with_user(appbox &$appbox, API_OAuth2_Application $application, User_Adapter $user)
|
||||
{
|
||||
$sql = 'SELECT api_account_id FROM api_accounts
|
||||
WHERE usr_id = :usr_id AND application_id = :application_id';
|
||||
|
||||
$params = array(
|
||||
":usr_id" => $user->get_id(),
|
||||
":application_id" => $application->get_id()
|
||||
);
|
||||
$params = array(
|
||||
":usr_id" => $user->get_id(),
|
||||
":application_id" => $application->get_id()
|
||||
);
|
||||
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
return new self($appbox, $row['api_account_id']);
|
||||
}
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
return new self($appbox, $row['api_account_id']);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -21,170 +21,167 @@
|
||||
*/
|
||||
class API_OAuth2_AuthCode
|
||||
{
|
||||
protected $appbox;
|
||||
protected $code;
|
||||
protected $account;
|
||||
protected $account_id;
|
||||
protected $redirect_uri;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
|
||||
protected $appbox;
|
||||
protected $code;
|
||||
protected $account;
|
||||
protected $account_id;
|
||||
protected $redirect_uri;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
|
||||
public function __construct(appbox &$appbox, $code)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->code = $code;
|
||||
$sql = 'SELECT code, api_account_id, redirect_uri, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
public function __construct(appbox &$appbox, $code)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->code = $code;
|
||||
$sql = 'SELECT code, api_account_id, redirect_uri, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
FROM api_oauth_codes WHERE code = :code';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->redirect_uri = $row['redirect_uri'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->redirect_uri = $row['redirect_uri'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_code()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if (!$this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
public function get_redirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
|
||||
public function set_redirect_uri($redirect_uri)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET redirect_uri = :redirect_uri
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':redirect_uri' => $redirect_uri, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET scope = :scope
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':scope' => $scope, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_codes WHERE code = :code';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_codes_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT code FROM api_oauth_codes
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$params = array(":account_id" => $account->get_id());
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$codes = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$codes[] = new API_OAuth2_AuthCode($appbox, $row['code']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
public function get_code()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param type $code
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_AuthCode
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $code, $expires)
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if ( ! $this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
$sql = 'INSERT INTO api_oauth_codes (code, api_account_id, expires)
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
public function get_redirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
|
||||
public function set_redirect_uri($redirect_uri)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET redirect_uri = :redirect_uri
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':redirect_uri' => $redirect_uri, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET scope = :scope
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':scope' => $scope, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_codes WHERE code = :code';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_codes_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT code FROM api_oauth_codes
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$params = array(":account_id" => $account->get_id());
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$codes = array();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$codes[] = new API_OAuth2_AuthCode($appbox, $row['code']);
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param type $code
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_AuthCode
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $code, $expires)
|
||||
{
|
||||
|
||||
$sql = 'INSERT INTO api_oauth_codes (code, api_account_id, expires)
|
||||
VALUES (:code, :account_id, FROM_UNIXTIME(:expires))';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$params = array(
|
||||
":code" => $code,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $code);
|
||||
}
|
||||
$params = array(
|
||||
":code" => $code,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -22,160 +22,158 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Exception extends Exception implements API_OAuth2_Exception_Interface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_uri;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_uri;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function __construct($http_code, $error, $error_description = null, $scope = null, $error_uri = null)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->error_description = $error_description;
|
||||
$this->scope = $scope;
|
||||
$this->error_uri = $error_uri;
|
||||
parent::__construct();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function __construct($http_code, $error, $error_description = null, $scope = null, $error_uri = null)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->error_description = $error_description;
|
||||
$this->scope = $scope;
|
||||
$this->error_uri = $error_uri;
|
||||
parent::__construct();
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttp_code()
|
||||
{
|
||||
return $this->http_code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttp_code()
|
||||
{
|
||||
return $this->http_code;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setHttp_code($http_code)
|
||||
{
|
||||
$this->http_code = $http_code;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setHttp_code($http_code)
|
||||
{
|
||||
$this->http_code = $http_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_description()
|
||||
{
|
||||
return $this->error_description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_description()
|
||||
{
|
||||
return $this->error_description;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_description($error_description)
|
||||
{
|
||||
$this->error_description = $error_description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_description($error_description)
|
||||
{
|
||||
$this->error_description = $error_description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_uri()
|
||||
{
|
||||
return $this->error_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_uri()
|
||||
{
|
||||
return $this->error_uri;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_uri($error_uri)
|
||||
{
|
||||
$this->error_uri = $error_uri;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_uri($error_uri)
|
||||
{
|
||||
$this->error_uri = $error_uri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -23,11 +23,11 @@
|
||||
interface API_OAuth2_Exception_Interface
|
||||
{
|
||||
|
||||
public function getError();
|
||||
public function getError();
|
||||
|
||||
public function getHttp_code();
|
||||
public function getHttp_code();
|
||||
|
||||
public function getError_description();
|
||||
public function getError_description();
|
||||
|
||||
public function getError_uri();
|
||||
public function getError_uri();
|
||||
}
|
||||
|
@@ -22,81 +22,81 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect extends API_OAuth2_Exception_Exception
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 302;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 302;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $state;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirect_uri;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function __construct($redirect_uri, $error, $error_description = null, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
$this->state = $state;
|
||||
parent::__construct($this->http_code, $error, $error_description, $error_uri);
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function __construct($redirect_uri, $error, $error_description = null, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
$this->state = $state;
|
||||
parent::__construct($this->http_code, $error, $error_description, $error_uri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setState($state)
|
||||
{
|
||||
$this->state = $state;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setState($state)
|
||||
{
|
||||
$this->state = $state;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setRedirect_uri($redirect_uri)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setRedirect_uri($redirect_uri)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_AccessDenied extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'access_denied';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'access_denied';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = " The resource owner or authorization server denied the request.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = " The resource owner or authorization server denied the request.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_AccessDenied
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_AccessDenied
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_InvalidClient extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_Client';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_Client';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The Client id is not valid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The Client id is not valid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_InvalidRequest extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidRequest
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidRequest
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,60 +22,58 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_InvalidScope extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_scope';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_scope';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The requested scope is invalid, unknown, or malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The requested scope is invalid, unknown, or malformed.";
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $scope
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function __construct($redirect_uri, $scope, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $scope
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function __construct($redirect_uri, $scope, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,29 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_ServerError extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'server_error';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'server_error';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server encountered an unexpected condition which prevented it from fulfilling the request.";
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server encountered an unexpected condition which prevented it from fulfilling the request.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_ServerError
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_ServerError
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_Unauthorized extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'temporarily_unavailable';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'temporarily_unavailable';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_Unauthorized
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_Unauthorized
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_UnauthorizedClient extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unauthorized_client';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unauthorized_client';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The client is not authorized to request an authorization code using this method.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The client is not authorized to request an authorization code using this method.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnauthorizedClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnauthorizedClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,60 +22,58 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_UnsupportedResponseType extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unsupported_response_type';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unsupported_response_type';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server does not support obtaining an authorization code using this method.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server does not support obtaining an authorization code using this method.";
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $method
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function __construct($redirect_uri, $method, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->method = $method;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $method
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function __construct($redirect_uri, $method, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->method = $method;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $method
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $method
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,58 +22,56 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate extends API_OAuth2_Exception_Exception
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $realm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $realm;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function __construct($http_code, $realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
$this->scope = $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function __construct($http_code, $realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
$this->scope = $scope;
|
||||
parent::__construct($http_code, $error, $error_description, $error_uri);
|
||||
|
||||
parent::__construct($http_code, $error, $error_description, $error_uri);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->realm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->realm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function setRealm($realm)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function setRealm($realm)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_ExpiredToken extends API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'expired_token';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'expired_token';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided has expired.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided has expired.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_ExpiredToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_ExpiredToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InsufficientScope extends API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'insufficient_scope';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'insufficient_scope';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request requires higher privileges than provided by the access token.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request requires higher privileges than provided by the access token.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InsufficientScope
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InsufficientScope
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InvalidClient extends API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidClient
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidClient
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InvalidRequest extends API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidRequest
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidRequest
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InvalidToken extends API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_token';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_token';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided is invalid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided is invalid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,27 +22,25 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest extends API_OAuth2_Exception_WWWAuthenticate
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 400;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 400;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -23,21 +23,20 @@
|
||||
class API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden extends API_OAuth2_Exception_WWWAuthenticate
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($realm, $error, $error_description = null, $error_uri, $scope);
|
||||
$this->setHttp_code(403);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($realm, $error, $error_description = null, $error_uri, $scope);
|
||||
$this->setHttp_code(403);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,27 +22,25 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized extends API_OAuth2_Exception_WWWAuthenticate
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $http_code = 401;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $http_code = 401;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -26,134 +26,132 @@ use Symfony\Component\Validator\Constraints;
|
||||
|
||||
class API_OAuth2_Form_DevAppDesktop
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
public $scheme_website;
|
||||
public $urlwebsite;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = API_OAuth2_Application::NATIVE_APP_REDIRECT_URI;
|
||||
$this->type = API_OAuth2_Application::DESKTOP_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
public $scheme_website;
|
||||
public $urlwebsite;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = API_OAuth2_Application::NATIVE_APP_REDIRECT_URI;
|
||||
$this->type = API_OAuth2_Application::DESKTOP_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -26,141 +26,137 @@ use Symfony\Component\Validator\Constraints;
|
||||
|
||||
class API_OAuth2_Form_DevAppInternet
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
|
||||
public $scheme_website;
|
||||
public $scheme_callback;
|
||||
|
||||
public $urlwebsite;
|
||||
public $urlcallback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = $request->get('callback', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->scheme_callback = $request->get('scheme-callback', 'http://');
|
||||
$this->type = API_OAuth2_Application::WEB_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website.$this->website;
|
||||
$this->urlcallback = $this->scheme_callback.$this->callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return $this->scheme_callback;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getUrlcallback()
|
||||
{
|
||||
return $this->urlcallback;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\Url($url));
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
public $scheme_website;
|
||||
public $scheme_callback;
|
||||
public $urlwebsite;
|
||||
public $urlcallback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = $request->get('callback', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->scheme_callback = $request->get('scheme-callback', 'http://');
|
||||
$this->type = API_OAuth2_Application::WEB_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||
$this->urlcallback = $this->scheme_callback . $this->callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return $this->scheme_callback;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getUrlcallback()
|
||||
{
|
||||
return $this->urlcallback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\Url($url));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -21,129 +21,126 @@
|
||||
*/
|
||||
class API_OAuth2_RefreshToken
|
||||
{
|
||||
protected $appbox;
|
||||
protected $token;
|
||||
protected $account_id;
|
||||
protected $account;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
|
||||
protected $appbox;
|
||||
protected $token;
|
||||
protected $account_id;
|
||||
protected $account;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
public function __construct(appbox &$appbox, $token)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->token = $token;
|
||||
|
||||
public function __construct(appbox &$appbox, $token)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->token = $token;
|
||||
|
||||
$sql = 'SELECT api_account_id, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
$sql = 'SELECT api_account_id, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
FROM api_oauth_refresh_tokens WHERE refresh_token = :token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':token' => $this->token));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':token' => $this->token));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if (!$this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_refresh_tokens
|
||||
WHERE refresh_token = :refresh_token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(":refresh_token" => $this->token));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT refresh_token FROM api_oauth_refresh_tokens
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $account->get_id()));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$tokens = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$tokens[] = new API_OAuth2_RefreshToken($appbox, $row['refresh_token']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param int $expires
|
||||
* @param type $refresh_token
|
||||
* @param type $scope
|
||||
* @return API_OAuth2_RefreshToken
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $expires, $refresh_token, $scope)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_refresh_tokens
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if ( ! $this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_refresh_tokens
|
||||
WHERE refresh_token = :refresh_token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(":refresh_token" => $this->token));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT refresh_token FROM api_oauth_refresh_tokens
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $account->get_id()));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$tokens = array();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$tokens[] = new API_OAuth2_RefreshToken($appbox, $row['refresh_token']);
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param int $expires
|
||||
* @param type $refresh_token
|
||||
* @param type $scope
|
||||
* @return API_OAuth2_RefreshToken
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $expires, $refresh_token, $scope)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_refresh_tokens
|
||||
(refresh_token, api_account_id, expires, scope)
|
||||
VALUES (:refresh_token, :account_id, :expires, :scope)';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(
|
||||
":refresh_token" => $refresh_token,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires,
|
||||
":scope" => $scope
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $refresh_token);
|
||||
}
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(
|
||||
":refresh_token" => $refresh_token,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires,
|
||||
":scope" => $scope
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $refresh_token);
|
||||
}
|
||||
}
|
||||
|
@@ -21,311 +21,309 @@
|
||||
*/
|
||||
class API_OAuth2_Token
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected $account;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $session_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $session_id;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expires;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expires;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function __construct(appbox &$appbox, API_OAuth2_Account &$account)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->account = $account;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function __construct(appbox &$appbox, API_OAuth2_Account &$account)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->account = $account;
|
||||
|
||||
$sql = 'SELECT oauth_token, session_id, UNIX_TIMESTAMP(expires) as expires, scope
|
||||
$sql = 'SELECT oauth_token, session_id, UNIX_TIMESTAMP(expires) as expires, scope
|
||||
FROM api_oauth_tokens
|
||||
WHERE api_account_id = :account_id';
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $this->account->get_id()));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $this->account->get_id()));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
$stmt->closeCursor();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->token = $row['oauth_token'];
|
||||
$this->session_id = is_null($row['session_id']) ? null : (int) $row['session_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
$this->token = $row['oauth_token'];
|
||||
$this->session_id = is_null($row['session_id']) ? null : (int) $row['session_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_value($oauth_token)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :oauth_token
|
||||
/**
|
||||
*
|
||||
* @param string $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_value($oauth_token)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :oauth_token
|
||||
WHERE oauth_token = :current_token';
|
||||
|
||||
$params = array(
|
||||
':oauth_token' => $oauth_token
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
$params = array(
|
||||
':oauth_token' => $oauth_token
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->token = $oauth_token;
|
||||
$this->token = $oauth_token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_session_id()
|
||||
{
|
||||
return $this->session_id;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_session_id()
|
||||
{
|
||||
return $this->session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $session_id
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_session_id($session_id)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET session_id = :session_id
|
||||
/**
|
||||
*
|
||||
* @param int $session_id
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_session_id($session_id)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET session_id = :session_id
|
||||
WHERE oauth_token = :current_token';
|
||||
|
||||
$params = array(
|
||||
':session_id' => $session_id
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
$params = array(
|
||||
':session_id' => $session_id
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->session_id = (int) $session_id;
|
||||
$this->session_id = (int) $session_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_expires($expires)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET expires = FROM_UNIXTIME(:expires)
|
||||
/**
|
||||
*
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_expires($expires)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET expires = FROM_UNIXTIME(:expires)
|
||||
WHERE oauth_token = :oauth_token';
|
||||
|
||||
$params = array(
|
||||
':expires' => $expires
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
$params = array(
|
||||
':expires' => $expires
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->expires = $expires;
|
||||
$this->expires = $expires;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET scope = :scope
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET scope = :scope
|
||||
WHERE oauth_token = :oauth_token';
|
||||
|
||||
$params = array(
|
||||
':scope' => $scope
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
$params = array(
|
||||
':scope' => $scope
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->scope = $scope;
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
return $this->account;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :new_token
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :new_token
|
||||
WHERE oauth_token = :old_token';
|
||||
|
||||
$new_token = self::generate_token();
|
||||
$new_token = self::generate_token();
|
||||
|
||||
$params = array(
|
||||
':new_token' => $new_token
|
||||
, ':old_token' => $this->get_value()
|
||||
);
|
||||
$params = array(
|
||||
':new_token' => $new_token
|
||||
, ':old_token' => $this->get_value()
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->token = $new_token;
|
||||
$this->token = $new_token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_tokens WHERE oauth_token = :oauth_token';
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_tokens WHERE oauth_token = :oauth_token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':oauth_token' => $this->get_value()));
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':oauth_token' => $this->get_value()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param type $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function load_by_oauth_token(appbox &$appbox, $oauth_token)
|
||||
{
|
||||
$sql = 'SELECT a.api_account_id
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param type $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function load_by_oauth_token(appbox &$appbox, $oauth_token)
|
||||
{
|
||||
$sql = 'SELECT a.api_account_id
|
||||
FROM api_oauth_tokens a, api_accounts b
|
||||
WHERE a.oauth_token = :oauth_token
|
||||
AND a.api_account_id = b.api_account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(":oauth_token" => $oauth_token);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(":oauth_token" => $oauth_token);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
$account = new API_OAuth2_Account($appbox, $row['api_account_id']);
|
||||
$account = new API_OAuth2_Account($appbox, $row['api_account_id']);
|
||||
|
||||
return new self($appbox, $account);
|
||||
}
|
||||
return new self($appbox, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account &$account, $scope = null)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_tokens
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account &$account, $scope = null)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_tokens
|
||||
(oauth_token, session_id, api_account_id, expires, scope)
|
||||
VALUES (:token, null, :account_id, :expire, :scope)';
|
||||
|
||||
$params = array(
|
||||
':token' => self::generate_token()
|
||||
, ':account_id' => $account->get_id()
|
||||
, ':expire' => time() + 3600
|
||||
, ':scope' => $scope
|
||||
);
|
||||
$params = array(
|
||||
':token' => self::generate_token()
|
||||
, ':account_id' => $account->get_id()
|
||||
, ':expire' => time() + 3600
|
||||
, ':scope' => $scope
|
||||
);
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new API_OAuth2_Token($appbox, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_token()
|
||||
{
|
||||
return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
|
||||
}
|
||||
return new API_OAuth2_Token($appbox, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_token()
|
||||
{
|
||||
return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user