You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a little confused regarding the OAuth authentication, specifically the call $auth->accessTokenUpdated(). It never seems to return true. As a result I have make a call to $auth->getAccessTokenData(); and store the results before the call to accessTokenUpdated. Am i missing something? Thanks
session_name("oauthtester");
session_start();
require dirname(__DIR__).'/vendor/autoload.php';
require 'settings.php';
use Mautic\Auth\ApiAuth;
use Mautic\MauticApi;
// ApiAuth::initiate will accept an array of OAuth settings
$settings = array(
'baseUrl' => $baseUrl, // Base URL of the Mautic instance
'version' => $version, // Version of the OAuth can be OAuth2 or OAuth1a. OAuth2 is the default value.
'clientKey' => $clientKey, // Client/Consumer key from Mautic
'clientSecret' => $clientSecret, // Client/Consumer secret key from Mautic
'callback' => $callback // Redirect URI/Callback URI for this script
);
if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {
$settings['accessToken'] = $_GET['oauth_token'];
$settings['accessTokenSecret'] = $_GET['oauth_verifier'];
}
// Initiate the auth object
$auth = ApiAuth::initiate($settings);
if (isset($_SESSION['accessTokenData'])) { //todo read from more permanent
$auth->setAccessTokenDetails(json_decode($_SESSION['accessTokenData'], true));
}
if ($auth->validateAccessToken()){
$accessTokenData = $auth->getAccessTokenData();
$_SESSION['accessTokenData'] = json_encode($accessTokenData); //todo save more permanently
if ($auth->accessTokenUpdated()) {
echo '333<br>';
$accessTokenData = $auth->getAccessTokenData();
//store access token data however you want
}
$leadApi = MauticApi::getContext("leads", $auth, $baseUrl .'/api/');
$leads = $leadApi->getList();
echo '$leads =' . print_r($leads, true);
Even if I make a call to $auth->getAccessTokenData(); and store the results before the call to accessTokenUpdated, I get token_rejected [code] => 401 when I call $leadApi->getList(). So I'm doing something wrong.
The text was updated successfully, but these errors were encountered:
I'm a little confused regarding the OAuth authentication, specifically the call $auth->accessTokenUpdated(). It never seems to return true. As a result I have make a call to $auth->getAccessTokenData(); and store the results before the call to accessTokenUpdated. Am i missing something? Thanks
My sample code based on sample from https://github.com/mautic/api-library:
Even if I make a call to $auth->getAccessTokenData(); and store the results before the call to accessTokenUpdated, I get token_rejected [code] => 401 when I call $leadApi->getList(). So I'm doing something wrong.
The text was updated successfully, but these errors were encountered: