Yii Framework Forum: How to set header for authentication restful api webservice - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to set header for authentication restful api webservice Rate Topic: -----

#1 User is offline   sepdau 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-May 12

Posted 04 May 2012 - 07:24 PM

I follow this tut http://www.yiiframew...-rest-api/#hh14
and I have a method for authentication is
private function _checkAuth() {

        // Check if we have the USERNAME and PASSWORD HTTP headers set?

        if (!(isset($_SERVER['HTTP_X_' . self::APPLICATION_ID . '_USERNAME']) and isset($_SERVER['HTTP_X_' . self::APPLICATION_ID . '_PASSWORD']))) {

            // Error: Unauthorized

            $this->_sendResponse(401);
        }

        $username = $_SERVER['HTTP_X_' . self::APPLICATION_ID . '_USERNAME'];

        $password = $_SERVER['HTTP_X_' . self::APPLICATION_ID . '_PASSWORD'];

        // Find the user

        $user = User::model()->find('LOWER(username)=?', array(strtolower($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 I can test this method by RESTClient addon
with header info
- name: ?
- value: ?
- body: ?
0

#2 User is offline   smyiia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 25-July 12

Posted 05 November 2012 - 07:03 PM

View Postsepdau, on 04 May 2012 - 07:24 PM, said:

I follow this tut http://www.yiiframew...-rest-api/#hh14
and I have a method for authentication is
private function _checkAuth() {

        // Check if we have the USERNAME and PASSWORD HTTP headers set?

        if (!(isset($_SERVER['HTTP_X_' . self::APPLICATION_ID . '_USERNAME']) and isset($_SERVER['HTTP_X_' . self::APPLICATION_ID . '_PASSWORD']))) {

            // Error: Unauthorized

            $this->_sendResponse(401);
        }

        $username = $_SERVER['HTTP_X_' . self::APPLICATION_ID . '_USERNAME'];

        $password = $_SERVER['HTTP_X_' . self::APPLICATION_ID . '_PASSWORD'];

        // Find the user

        $user = User::model()->find('LOWER(username)=?', array(strtolower($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 I can test this method by RESTClient addon
with header info
- name: ?
- value: ?
- body: ?

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users