[英]Authentication in header Rest Api
I am working with rest api
in codeigniter and I want to add api-authentication
,so for this I am sending access_token
in header section of postman, but I want to know that how can I get it in .php
file. 我正在使用codeigniter中的
rest api
,并且我想添加api-authentication
,因此,我要在邮递员的标头部分发送access_token
,但我想知道如何在.php
文件中获取它。 I just want the person who try to hit api without access_token
or wrong access_token
should not get api results. 我只希望尝试在没有
access_token
或错误的access_token
情况下尝试api的人不应该获得api结果。 In my controller
I put following code. 在我的
controller
我输入了以下代码。 How can I add authentication on rest api ? 如何在rest api上添加身份验证?
if ($access_token!= $_POST['access_token']) {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
} else {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'any text';
}
If you are creating RESTful server in codeigniter, consider using https://github.com/chriskacerguis/codeigniter-restserver library. 如果要在codeigniter中创建RESTful服务器,请考虑使用https://github.com/chriskacerguis/codeigniter-restserver库。
And for API authentication implementation in codeigniter, consider using https://github.com/ParitoshVaidya/CodeIgniter-JWT-Sample . 对于在codeigniter中进行API身份验证的实现,请考虑使用https://github.com/ParitoshVaidya/CodeIgniter-JWT-Sample 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.