Exemplo n.º 1
0
 /**
  * get access token of from service, has to be called after successful authorization
  *
  * @param string $code optional, if no code given method tries to get it out of $_GET
  */
 public function getAccessToken($code = null)
 {
     if (!$code) {
         if (!isset($_GET['code'])) {
             throw new OAuth2_Exception('could not retrieve code out of callback request and no code given');
         }
         $code = $_GET['code'];
     }
     $parameters = array('grant_type' => 'authorization_code', 'type' => 'web_server', 'client_id' => $this->_client->getClientKey(), 'client_secret' => $this->_client->getClientSecret(), 'redirect_uri' => $this->_client->getCallbackUrl(), 'code' => $code);
     if ($this->_scope) {
         $parameters['scope'] = $this->_scope;
     }
     if ($this->_state) {
         $parameters['state'] = $this->_state;
     }
     $http = new OAuth2_HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST', http_build_query($parameters));
     $http->execute();
     $this->_parseAccessTokenResponse($http);
 }