Skip to content

Instantly share code, notes, and snippets.

Created April 8, 2013 07:52
Show Gist options
  • Save anonymous/5335009 to your computer and use it in GitHub Desktop.
Save anonymous/5335009 to your computer and use it in GitHub Desktop.
Request OAuth access token --- *@param  string $code* OAuth code we got from service *@return* string Token, or null if we didn't obtain a proper token
 /**
    * Request OAuth access token
    *
    * @param  string $code OAuth code we got from service
    * @return string Token, or null if we didn't obtain a proper token
    */
   protected function _requestToken($code)
   {
       $config = $this->_config->oauth;
       $client = new \Zend_Http_Client("http://accounts.tunehog.com/oauth/token");
       $client->setParameterPost([
           'grant_type' => 'authorization_code',
           'client_id' => $config->client_id,
           'client_secret' => $config->client_secret,
           'code' => $code,
       ]);
       if ($response = $this->_helper->http->request($client, 'POST')) {
           $response = \Zend_Json::decode($response->getBody(), \Zend_Json::TYPE_OBJECT);
           if (isset($response->access_token)) {
               return $response->access_token;
           }
       }
   }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment