/** * Execute access token request and return response retuned by server * * @param string $_tokenEndPoint token end point url * @param array $_params list of parameters required to execute request * @param int $_clientAuthType client authentication type * @param array any additional header that needs to be sent e.g. array('Conent-Type' =>'application/json'); * @param string method method type e.g. 'GET', 'POST', 'DELETE', 'PUT' * * @return mixed response retuned by server * @throws SWIFT_OAuth2Exception if failed to execute request */ public function AccessTokenRequest($_tokenEndPoint, array $_params, $_clientAuthType = self::AUTH_TYPE_AUTHORIZATION_FORM, array $_headers = array(), $_method = 'POST') { $_params = $this->CheckTokenRequestParams($_params); if (($_clientAuthType == self::AUTH_TYPE_AUTHORIZATION_FORM || $_clientAuthType == self::AUTH_TYPE_AUTHORIZATION_BASIC) && (!isset($_params['client_id']) || !isset($_params['client_secret']))) { throw new SWIFT_OAuth2Exception('AUTH_TYPE_AUTHORIZATION_FORM requires client_id and client_secret to be given in params'); } if ($_clientAuthType == self::AUTH_TYPE_AUTHORIZATION_BASIC && !isset($_headers['Authorization'])) { $_headers['Authorization'] = 'Basic ' . base64_encode($_params['client_id'] . ':' . $_params['client_secret']); } $_params = $this->ChangeParamNames($_params); //execute request $_CurlInstance = SWIFT_HttpCurl::GetInstance(); $_paramsStr = http_build_query($_params); $_defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; $_headers = $_headers + $_defaultHeaders; return $_CurlInstance->SendRequest($_tokenEndPoint, $_paramsStr, $_method, $_headers); }