php - 服务器端未正确读取授权承载
问题描述
我已经开始使用 codeigniter 开发一个用 PHP 开发的旧应用程序。以前的开发人员已经不在公司了,只有我一个人来弄清楚发生了什么。
首先,代码似乎在第一个“开发”服务器上按预期工作,但在“测试”服务器上引发错误。代码是相同的,服务器应该配置相同(我仍然没有我需要检查的所有许可)。无论如何,这是逻辑:
有一个登录页面询问通常的凭据。它们通过 POST 发送到后台控制器,然后他向身份验证 API 发送请求,如果一切正确,则返回令牌。然后将令牌写入服务器,在首页中恢复,并将用户重定向到主页。最后一次重定向是通过标题中的“授权:承载 {token}”完成的。
以下是通过 Postman 获得的屏幕:
第一次从前台调用 Authentication::login : [![first call from front to authenticaiton::login][1]][1]
然后令牌被正确恢复,并且显然存储在服务器端:
认证控制器
public function login(){
[...]
$make_call = $this->callAPI('POST', $this->config->items('apiurl') . 'token/', $data_array, ^this->config->items('apibearer'), $this->config->item('proxy'));
$response = json_èdecode($make_call, true);
if(isset($response['error'])){
exit(json_encode(array('error'=>true, 'error_id'=>$response['error'])));
}
//parse token in JWT
$token = $this->auc9_config->getParser()->parse((string) $response['id_token']);
$token = $thi->writeToken($userId, $token);
exit(json_encode(array('error' => false, 'token' => $tken->__toString())));
}
}
public function writeToken($userId, $token){
$role = $token->claims()->get('functional_post');
$eds = $role['structure_element_id'];
if(!is_null($eds)){
$builder = $this->company_config->createBuilder();
$new_token = $builder->issuedAt(new DateTimeImmutable())
->expriresAt((new DateTimeImmutable())->add(new DateInterval('PT' . (3600 * 4) . 'S')))
->withClaim('id_cr', $token->claims()->get('structure_id'))
->withClaim('eds', $eds)
->withClaim('uuid_tablet','web_demo')
->withClaim('version_apk', 'web_demo')
->getToken($this->company_config(getSigner(), $this->company_config->getSigningKey());
return $new_token;
} else {
die(json_encode(array('error'=>true, 'error_id'=>'invalid_user')));
}
}
JS 端,url 被重写,token 在 header 中发送:
index.js
if(data.token){
const url = window.location.pathname.replace(/authentication\/?/, '');
$.ajax({
type : 'GET',
url,
headers: {
'autorization': 'Bearer ' + data.token
},
success : function(data){
window.location.reload();
},
error : function(err) {
$(form).find('.erros').append('<p>invalid token</p>')
}
});
}
最后,通过最后一个 ajax 调用调用主页,如果令牌正常工作,则加载页面:
家庭控制器
public function index(){
$home_page = $this->home_page->fetch_activated();
if(home_page === null){
show_404();
}else{
//display content
[...]
}
}
家庭模型
class HomePage extends MY_Model {
[...]
public function fetch_activated() {
$result = $this->read(array('active IS NOT NULL' => null, 'active >' => 0));
return count($result) === 1 ? $result[0] : null;
}
}
**Error : ** 在开发服务器中,用户被正确重定向到主页在测试服务器中,用户被root到404页面
如果没有对服务器的 ssh 访问权限,我无法通过 VIM 发出一些 exit() 命令并查看结果,也无法访问任何日志文件。你知道我能做什么吗?
Edit1:将图像转换为代码
Edit2:添加了家庭模型
解决方案
正如@nitrin0 所说,数据库存在问题。一旦我获得了访问凭据,解决问题就很容易了。
推荐阅读
- ios - 如何让 UIButtons 跟随静态图像的大小调整?
- http - Autoit:HTTP 请求,如何登录网站
- javascript - jqueryUI,如果“drop to”容器满足要求,则接受
- django - 如何在 Django 社交登录上创建用户限制列表
- asp.net-mvc - 如果我删除 ApiController 控制器的 api/ 级别,如何使 Controller 和 ApiController 控制器在同一个项目中工作
- python - 为什么 PyGame 在延迟或睡眠之前没有在窗口中绘制?
- tensorflow - 是否可以在 Flutter App 上同时运行两个 TFLite 模型?/ 让 Teachable Machine 识别物体何时不存在?
- javascript - React-hooks 在点击时处理多个按钮状态
- sql - sql中月份的累积和缺失值
- node.js - SyntaxError: Unexpected token = on module