授权持有人未正确读取 server-side
The authorisation bearer isn't read correctly server-side
我已经开始使用 codeigniter 开发在 PHP 中开发的旧应用程序。之前的dev不在公司了,我一个人搞清楚怎么回事。
首先,代码似乎在第一个“开发”服务器上按预期工作,但在“测试”服务器上引发错误。代码是相同的,服务器的配置应该相同(我仍然没有检查这个所需的所有许可)。无论如何,这是逻辑:
有一个 登录 页面询问通常的凭据。它们通过 POST 发送到后台控制器,然后他向身份验证 API 发送一个请求,如果一切正确,returns 一个令牌。
然后将令牌写入服务器,在首页恢复,并将用户重定向到主页。最后一次重定向是通过 header.
中的“autorization: Bearer {token}”完成的
这是通过 Postman 获得的屏幕:
第一次从前面打电话给Authentication::login:
[![从前面第一次调用 authenticaiton::login][1]][1]
令牌随后被正确恢复,并且显然被存储 server-side :
认证控制器
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 并在 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;
}
}
**错误:**
在开发服务器中,用户被正确重定向到首页
在测试服务器中,用户root到404页面
没有对服务器的 ssh 访问权限,我无法通过 VIM 发出一些 exit() 命令并查看结果,也无法访问任何日志文件。
你知道我能做什么吗?
Edit1:将图像转换为代码
Edit2:添加了家庭模型
如@nitrin0 所述,数据库出现问题。获得访问凭据后,解决问题就非常容易了。
我已经开始使用 codeigniter 开发在 PHP 中开发的旧应用程序。之前的dev不在公司了,我一个人搞清楚怎么回事。
首先,代码似乎在第一个“开发”服务器上按预期工作,但在“测试”服务器上引发错误。代码是相同的,服务器的配置应该相同(我仍然没有检查这个所需的所有许可)。无论如何,这是逻辑:
有一个 登录 页面询问通常的凭据。它们通过 POST 发送到后台控制器,然后他向身份验证 API 发送一个请求,如果一切正确,returns 一个令牌。 然后将令牌写入服务器,在首页恢复,并将用户重定向到主页。最后一次重定向是通过 header.
中的“autorization: Bearer {token}”完成的这是通过 Postman 获得的屏幕:
第一次从前面打电话给Authentication::login: [![从前面第一次调用 authenticaiton::login][1]][1]
令牌随后被正确恢复,并且显然被存储 server-side :
认证控制器
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 并在 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;
}
}
**错误:** 在开发服务器中,用户被正确重定向到首页 在测试服务器中,用户root到404页面
没有对服务器的 ssh 访问权限,我无法通过 VIM 发出一些 exit() 命令并查看结果,也无法访问任何日志文件。 你知道我能做什么吗?
Edit1:将图像转换为代码
Edit2:添加了家庭模型
如@nitrin0 所述,数据库出现问题。获得访问凭据后,解决问题就非常容易了。