[英]How to set header for restful api authentication using RESTclient Addon Firefox
I have this code from Yii Example 我有来自Yii Example的这段代码
private function _checkAuth()
{
// Check if we have the USERNAME and PASSWORD HTTP headers set?
if(!(isset($_SERVER['HTTP_X_USERNAME']) and isset($_SERVER['HTTP_X_PASSWORD']))) {
// Error: Unauthorized
$this->_sendResponse(401);
}
$username = $_SERVER['HTTP_X_USERNAME'];
$password = $_SERVER['HTTP_X_PASSWORD'];
// Find the user
$user=User::model()->find('LOWER(username)=?',array(strtolower($username)));
$this->_sendResponse('200','$username');
if($user===null) {
// Error: Unauthorized
$this->_sendResponse(401, 'Error: User Name is invalid');
}
else if(!$user->validatePassword($password)) {
// Error: Unauthorized
$this->_sendResponse(401, 'Error: User Password is invalid');
}
}
How to set header information for authentication. 如何设置标题信息以进行认证。 How to set HTTP_X_USERNAME and HTTP_X_PASSWORD in request;
如何在请求中设置HTTP_X_USERNAME和HTTP_X_PASSWORD;
for the name, value and body of RESTClient addon? RESTClient插件的名称,值和主体? Thank for advance
感谢提前
Hi I have resolved this issue with following server side code, set the HTTP Request headers as you are already doing on client side. 嗨,我已经通过以下服务器端代码解决了此问题,就像在客户端上一样设置HTTP请求标头。
private function _checkAuth()
{
// Check if we have the USERNAME and PASSWORD HTTP headers set?
$headers = apache_request_headers();
if(!(isset($headers['X_'.self::APPLICATION_ID.'_USERNAME']) and isset($headers['X_'.self::APPLICATION_ID.'_PASSWORD']))) {
// Error: Unauthorized
$this->_sendResponse(401);
}
$username = $headers['X_'.self::APPLICATION_ID.'_USERNAME'];
$password = $headers['X_'.self::APPLICATION_ID.'_PASSWORD'];
}
I understand your question (same as this post in yii forum ) relates to the RESTClient addon. 我了解您的问题(与yii论坛中的帖子相同)与RESTClient插件有关。 To set your headers in the RESTClient addon: use the 'headers' functionality:
要在RESTClient插件中设置标题,请使用“标题”功能:
And the same with X_USERNAME. 与X_USERNAME相同。
HTH, HTH,
JM. JM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.