Search code examples
phpoauthyiiyii-extensions

Yii OAuth Implementation


Requiremen :- Yii, OAuth implemenation to authenticate and fetch user data. I found out that there are two extensions. Eauth(support OAuth 2.0 and other social networking sites) and Eoauth(OAuth 1.0). Correct me If i am wrong.

I dont have to authenticate any social networking site. It's a different url from where I need to get the data.

Now i could successfully login and authenticate using "eoauth" extension but also I need to fetch information about the user. I don't find any function or way how to fetch data from url which lies under OAuth layer. Does Eauth or Eoauth supports fetching or it has to be custom coded ? If this extensions does not do this then what is the other way I can authenticate and fetch data ?


Solution

  • Though Old but You just need to use CURL request to the end URL and you will get your data. I guess those modules doesn't have the function to fetch a data. I hope this might help you. I have used in one of my code and It was successful

    public function GetData($url){
            $signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
            $request = OAuthRequest::from_consumer_and_token($this->consumer,$this->token, 'GET',    $url, array());
            $request->sign_request($signatureMethod, $this->consumer, $this->token);        
            $fetchUrl = $request->to_url();
            $response = Yii::app()->CURL->run($fetchUrl);     
            return json_decode($response);               
        }