westdc-zf1/application/module/Open/OAuth2/Server.php

76 lines
1.3 KiB
PHP

<?php
namespace Open\OAuth2;
use \Helpers\View as view;
use \Helpers\Table;
class Server extends \Zend_Controller_Plugin_Abstract
{
public $db;
public $auth = NULL;
public $user;
private $config;
public $table;
public function __construct($db = NULL,$auth = NULL){
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
$this->table = new Table();
}
//根据ID或者Client_id获得app的信息
public function getClientInfo($id)
{
if(empty($id))
{
return "无效参数";
}
if(is_numeric($id))
{
$field = "id";
}else{
$field = "client_id";
}
$sql = "SELECT * FROM {$this->table->oauth_clients} WHERE $field=? LIMIT 1";
$sth = $this->db->prepare($sql);
$sth->execute(array($id));
$row = $sth->fetch();
return $row;
}
//验证App
public function clientCredentials($client_id,$client_secret)
{
$client = $this->getClientInfo($client_id);
if(empty($client['id']))
{
return "此应用ID未被证实";
}
if($client['status'] == -1)
{
return "此应用已关闭";
}
if($client['client_secret'] !== $client_secret)
{
return "Invalid client secret";
}
return true;
}
}