Changes on Designer Controller to pass client credentials and authorization_code on designer ui loading
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
|
||||
class Designer extends Controller
|
||||
{
|
||||
protected $clientId = 'x-pm-local-client';
|
||||
|
||||
public function __construct ()
|
||||
{
|
||||
|
||||
@@ -22,11 +24,50 @@ class Designer extends Controller
|
||||
public function index($httpData)
|
||||
{
|
||||
$proUid = isset($httpData->pro_uid) ? $httpData->pro_uid : '';
|
||||
$client = $this->getClientCredentials();
|
||||
$authCode = $this->getAuthorizationCode($client);
|
||||
|
||||
$this->setVar('pro_uid', $proUid);
|
||||
$this->setVar('prj_uid', $proUid);
|
||||
$this->setVar('client_id', $client['CLIENT_ID']);
|
||||
$this->setVar('secret', $client['CLIENT_SECRET']);
|
||||
$this->setVar('authorization_code', $authCode);
|
||||
$this->setView('designer/index');
|
||||
|
||||
$this->render();
|
||||
}
|
||||
|
||||
protected function getClientCredentials()
|
||||
{
|
||||
$oauthQuery = new Services\Api\OAuth2\PmPdo($this->getDsn());
|
||||
return $oauthQuery->getClientDetails($this->clientId);
|
||||
}
|
||||
|
||||
protected function getAuthorizationCode($client)
|
||||
{
|
||||
\Services\Api\OAuth2\Server::setDatabaseSource($this->getDsn());
|
||||
\Services\Api\OAuth2\Server::setPmClientId($client['CLIENT_ID']);
|
||||
|
||||
$oauthServer = new \Services\Api\OAuth2\Server();
|
||||
$userId = $_SESSION['USER_LOGGED'];
|
||||
$authorize = true;
|
||||
$_GET = array_merge($_GET, array(
|
||||
'response_type' => 'code',
|
||||
'client_id' => $client['CLIENT_ID'],
|
||||
'scope' => implode(' ', $oauthServer->getScope())
|
||||
));
|
||||
|
||||
$response = $oauthServer->postAuthorize($authorize, $userId, true);
|
||||
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
private function getDsn()
|
||||
{
|
||||
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
||||
$port = empty($port) ? '' : ";port=$port";
|
||||
$dsn = DB_ADAPTER.':host='.$host.';dbname='.DB_NAME.$port;
|
||||
|
||||
return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,11 +63,17 @@ class Server implements iAuthenticate
|
||||
$this->server->setScopeUtil($scope);
|
||||
}
|
||||
|
||||
public static function setDatabaseSource($user, $password, $dsn)
|
||||
public static function setDatabaseSource($user, $password = '', $dsn = '')
|
||||
{
|
||||
self::$dbUser = $user;
|
||||
self::$dbPassword = $password;
|
||||
self::$dsn = $dsn;
|
||||
if (is_array($user)) {
|
||||
self::$dbUser = $user['username'];
|
||||
self::$dbPassword = $user['password'];
|
||||
self::$dsn = $user['dsn'];
|
||||
} else {
|
||||
self::$dbUser = $user;
|
||||
self::$dbPassword = $password;
|
||||
self::$dsn = $dsn;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,4 +230,9 @@ class Server implements iAuthenticate
|
||||
{
|
||||
return self::$userId;
|
||||
}
|
||||
|
||||
public function getScope()
|
||||
{
|
||||
return array_keys($this->scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
<link rel="stylesheet" type="text/css" href="/lib/css/jquery-ui-1.10.3.custom.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/lib/css/jquery.dataTables.css">
|
||||
|
||||
<script type="text/javascript">
|
||||
var prj_uid = "{$prj_uid}";
|
||||
var client_id = "{$client_id}";
|
||||
var secret = "{$secret}";
|
||||
var authorization_code = "{$authorization_code}";
|
||||
</script>
|
||||
<script type="text/javascript" src="/lib/js/wz_jsgraphics.js"></script>
|
||||
<script type="text/javascript" src="/lib/js/jquery-1.10.2.min.js"></script>
|
||||
<script type="text/javascript" src="/lib/js/underscore-min.js"></script>
|
||||
@@ -14,6 +20,4 @@
|
||||
<script type="text/javascript" src="/lib/js/jquery.dataTables.min.js"></script>
|
||||
<script type="text/javascript" src="/lib/pmUI/pmui-1.0.0.js"></script>
|
||||
<script type="text/javascript" src="/lib/mafe/mafe.min.js"></script>
|
||||
<script type="text/javascript" src="/lib/mafe/designer.js"></script>
|
||||
|
||||
<h3>Process Id: {$pro_uid}</h3>
|
||||
<script type="text/javascript" src="/lib/mafe/designer.js"></script>
|
||||
Reference in New Issue
Block a user