How to set header for api authentication check using RESTclient Addon Firefox

I have this code from 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 configure header information for authentication. How to set HTTP_X_USERNAME and HTTP_X_PASSWORD in a request;

for the name, value and body of the RESTClient addon? Thanks for advance

+3
source share
2 answers

I understand your question (just like this post in the yii forum ) relates to the RESTClient addon. To configure headers in the RESTClient addon: use the headers functionality:

  • List item
  • Headers menu
  • 'Custom header'
  • 'Name': X_PASSWORD
  • "Value": emo

And the same with X_USERNAME.

NTN

Jm.

+4

. , 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'];
}
+6

All Articles