【发布时间】:2017-05-18 15:38:08
【问题描述】:
我的 Web 服务需要 API 提供程序(数据库选择/插入、文件夹/文件编辑/创建/删除操作等)
我为 oauth2 找到了这个库 https://github.com/bshaffer/oauth2-server-php
到目前为止,我已经能够关注tutorial/documentation 低谷,并且可以进行身份验证和访问 api。
问题是该示例很简单,并且没有显示为经过身份验证的用户传递附加参数(例如 mycustomaction=myustomvalue)的方法。
处理资源的代码如下
// include our OAuth2 Server object
require_once __DIR__.'/server.php';
// Handle a request to a resource and authenticate the access token
if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$server->getResponse()->send();
die;
}
echo json_encode(array('success' => true, 'message' => 'You accessed my APIs!'));
我需要的类似东西的伪代码
// include our OAuth2 Server object
require_once __DIR__.'/server.php';
// Handle a request to a resource and authenticate the access token
if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$server->getResponse()->send();
die;
}else{
if($customvalue){
//get the custom value and run code for it.
}
echo json_encode(array('success' => true, 'message' => 'You accessed my APIs!'));
}
有没有办法用这个库做我需要的事情?
附:我选择了这个库,因为它是唯一一个有我可以学习的工作教程的库。我无法在客户端安装其他库(因此是简单的包含文件)
【问题讨论】:
标签: php oauth-2.0 access-token