50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
|
<?php
|
||
|
namespace Open;
|
||
|
|
||
|
class Server extends \Zend_Controller_Plugin_Abstract
|
||
|
{
|
||
|
public $db;
|
||
|
public $auth = NULL;
|
||
|
public $user;
|
||
|
private $config;
|
||
|
|
||
|
public function __construct($db = NULL,$auth = NULL){
|
||
|
$this->config = \Zend_Registry::get('config');
|
||
|
if(empty($db))
|
||
|
{
|
||
|
$this->db = \Zend_Registry::get('db');
|
||
|
}else{
|
||
|
$this->db = $db;
|
||
|
}
|
||
|
|
||
|
if(empty($auth))
|
||
|
{
|
||
|
$this->auth = \Zend_Auth::getInstance();
|
||
|
if($this->auth->hasIdentity())
|
||
|
{
|
||
|
$this->user = $this->auth->getIdentity();
|
||
|
}
|
||
|
}else{
|
||
|
$this->auth = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function bootstrap()
|
||
|
{
|
||
|
$dsn = "pgsql:dbname={$this->config->db->params->dbname};host={$this->config->db->params->host}";
|
||
|
|
||
|
$storage = new \OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $this->config->db->params->username, 'password' => $this->config->db->params->password));
|
||
|
|
||
|
$server = new \OAuth2\Server($storage);
|
||
|
|
||
|
$server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
|
||
|
|
||
|
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
|
||
|
|
||
|
//应用授权
|
||
|
//$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
|
||
|
|
||
|
return $server;
|
||
|
}
|
||
|
|
||
|
}
|