This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php
T
Yuri Kuznetsov ed37380d8e oauth
2014-09-10 18:27:15 +03:00

76 lines
1.4 KiB
PHP

<?php
namespace Espo\Core\ExternalAccount\Clients;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\ExternalAccount\OAuth2\Client;
abstract class OAuth2Abstract
{
protected $client = null;
protected $paramList = array(
'endpoint',
'tokenEndpoint',
'clientId',
'clientSecret',
'accessToken',
'refreshToken',
'redirectUri'
);
protected $clientId = null;
protected $clientSecret = null;
protected $accessToken = null;
protected $refreshToken = null;
protected $redirectUri = null;
public function __construct($client, array $params = array())
{
$this->client = $client;
$this->setParams($params);
}
public function getParam($name)
{
if (in_array($name, $this->paramList)) {
return $this->$name;
}
}
public function setParam($name, $value)
{
if (in_array($name, $this->paramList)) {
$methodName = 'set' . ucfirst($name);
if (method_exists($this->client, $methodName)) {
$this->client->$methodName($value);
}
$this->$name = $value;
}
}
public function setParams($params)
{
foreach ($this->paramList as $name) {
if (!empty($params[$name])) {
$this->setParam($name, $params[$name]);
}
}
}
public function getAccessTokenFromAuthorizationCode($code)
{
return $this->client->getAccessToken($this->getParam('tokenEndpoint'), Client::GRANT_TYPE_AUTHORIZATION_CODE, array(
'code' => $code,
'redirect_uri' => $this->getParam('redirectUri')
));
}
}