protected function getAuth() { $this->config = (include __DIR__ . '/../local.config.php'); $auth = ApiAuth::initiate($this->config); $this->assertTrue($auth->isAuthorized(), 'Authorization failed. Check credentials in local.config.php.'); return array($auth, $this->config['apiUrl']); }
public function getAccessTokenData() { $auth = ApiAuth::initiate($this->settings); $accessTokenData = []; if ($auth->validateAccessToken()) { if ($auth->accessTokenUpdated()) { $accessTokenData = $auth->getAccessTokenData(); } } return $accessTokenData; }
} if ($valid) { $_SESSION['settings']['OAuth1a']['consumerKey'] = $consumerKey; $_SESSION['settings']['OAuth1a']['consumerSecret'] = $consumerSecret; $_SESSION['settings']['OAuth1a']['callback'] = $callback; $_SESSION['settings']['OAuth2']['clientKey'] = $clientKey; $_SESSION['settings']['OAuth2']['clientSecret'] = $clientSecret; $_SESSION['settings']['OAuth2']['redirectUri'] = $redirectUri; $_SESSION['settings']['OAuth2']['scope'] = $scope; $_SESSION['settings']['OAuth2']['state'] = $state; $_SESSION['auth'] = $auth; $_SESSION['apiendpoint'] = $apiendpoint; $_SESSION['responsetype'] = $responsetype; $_SESSION['method'] = $method; $_SESSION['parameters'] = $parameters; $oauthObject = \Mautic\Auth\ApiAuth::initiate(array('baseUrl' => $oauthBaseUrl, 'version' => $auth, 'clientKey' => $auth == 'OAuth1a' ? $consumerKey : $clientKey, 'clientSecret' => $auth == 'OAuth1a' ? $consumerSecret : $clientSecret, 'callback' => $callback, 'scope' => $scope)); if (!empty($_SESSION[$auth])) { $oauthObject->setAccessTokenDetails($_SESSION[$auth]); } $oauthObject->enableDebugMode(); try { if ($oauthObject->validateAccessToken()) { //Was the access token updated? if ($oauthObject->accessTokenUpdated()) { $_SESSION[$auth] = $oauthObject->getAccessTokenData(); } if (!empty($_POST['apiurl'])) { $url = $apiurl . '/api/' . $apiendpoint; if ($responsetype != '/') { $url .= $responsetype; }
/** * Initiate Auth object * * @return string */ public function getMauticAuth($clearAccessToken = false) { $settings = $this->getApiSettings(); if ($clearAccessToken) { unset($settings['accessToken']); unset($settings['accessTokenSecret']); unset($settings['accessTokenExpires']); unset($settings['refreshToken']); unset($_SESSION['OAuth1a']); unset($_SESSION['OAuth2']); unset($_SESSION['oauth']); } return \Mautic\Auth\ApiAuth::initiate($settings); }