# Cannot access Oauth class from ApiAuth

**URL:** https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955
**Category:** Product Support
**Created:** [December 12, 2015, 2:08pm UTC](https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955 "2015-12-12T14:08:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)
#### Post date: [December 12, 2015, 2:08pm UTC](https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955/1 "2015-12-12T14:08:34Z")

</div>

Hi there,  
  
I am building my own extension which should send newly entered e-mail directly to Mautic. I am targeting that to be a Wordpress plugin (I know one exists, I am trying to build slightly different one)  
  
  
  
I started by reading this:  
  
[https://www.mautic.org/blog/how-to-use-the-mautic-rest-api/](https://www.mautic.org/blog/how-to-use-the-mautic-rest-api/)  
  
  
  
From that, I downloaded the API as ZIP file and included “lib” subdirectory to my directory plugin.  
  
  
  
Now, when trying to authorise with Mautic, I start like this:

Code:

function send\_to\_mautic\_after\_payment( $payment\_id, $payment\_data ){ require(plugin\_dir\_path(\_\_FILE\_\_) . 'lib/MauticApi.php'); require(plugin\_dir\_path(\_\_FILE\_\_) . 'lib/Auth/ApiAuth.php'); global $global\_options;

$edd\_mautic\_settings = array(  
‘baseUrl’ =\> $global\_options[‘mautic\_base\_url’],  
‘clientKey’ =\> $global\_options[‘mautic\_public\_key’],  
‘clientSecret’ =\> $global\_options[‘mautic\_secret\_key’],  
‘callback’ =\> get\_base\_url(),  
‘version’ =\> ‘OAuth1a’  
);

$auth = MauticAuthApiAuth::initiate($edd\_mautic\_settings);  
if ($auth-\>validateAccessToken()) {  
if ($auth-\>accessTokenUpdated()) {  
$accessTokenData = $auth-\>getAccessTokenData();  
// @todo Save $accessTokenData  
// @todo Display success authorization message  
} else {  
// @todo Display info message that this app is already authorized.  
}  
} else {  
// @todo Display info message that the token is not valid.  
}  
}

  
Now, I know that code is pretty basic skeleton, but even running this, I am getting this error:

Code:

 Fatal error: Class 'MauticAuthOAuth' not found in /wp-content/plugins/paymenttomautic/lib/Auth/ApiAuth.php on line 45 

  
The 'ApiAuth.php' itself is something provided by the API zip file itself. The code around line 45 says this:  

Code:

public function newAuth($parameters = array(), $authMethod = 'OAuth') { $class = 'Mautic\Auth\'.$authMethod; $authObject = new $class(); //... and continued...

  
Seems to me that this piece code is trying to access the 'OAuth.php' file located in same directory, but is unable to.  
  
I am pretty much clueless what should I do next in order to unblock this and see if I am getting correctly to mautic API. Thanks for help

---

<div class="post-metadata">

### Author: ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)
#### Post date: [December 12, 2015, 2:08pm UTC](https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955/2 "2015-12-12T14:08:34Z")

</div>

Hi there,  
I am building my own extension which should send newly entered e-mail directly to Mautic. I am targeting that to be a Wordpress plugin (I know one exists, I am trying to build slightly different one)

I started by reading this:  
[https://www.mautic.org/blog/how-to-use-the-mautic-rest-api/](https://www.mautic.org/blog/how-to-use-the-mautic-rest-api/)

From that, I downloaded the API as ZIP file and included “lib” subdirectory to my directory plugin.

Now, when trying to authorise with Mautic, I start like this:

```auto
function send_to_mautic_after_payment( $payment_id, $payment_data ){
 require(plugin_dir_path( __FILE__ ) . 'lib/MauticApi.php');
 require(plugin_dir_path( __FILE__ ) . 'lib/Auth/ApiAuth.php');
 global $global_options;

$edd_mautic_settings = array(
    'baseUrl' => $global_options['mautic_base_url'],
    'clientKey' => $global_options['mautic_public_key'],
    'clientSecret' => $global_options['mautic_secret_key'],
    'callback' => get_base_url(), 
    'version' => 'OAuth1a'
);   

$auth = MauticAuthApiAuth::initiate($edd_mautic_settings);
 if ($auth->validateAccessToken()) {
    if ($auth->accessTokenUpdated()) {
        $accessTokenData = $auth->getAccessTokenData();
        // @todo Save $accessTokenData
        // @todo Display success authorization message
    } else {
        // @todo Display info message that this app is already authorized.
    }
} else {
    // @todo Display info message that the token is not valid.
}
}
```

Now, I know that code is pretty basic skeleton, but even running this, I am getting this error:

```auto
 Fatal error: Class 'MauticAuthOAuth' not found in /wp-content/plugins/paymenttomautic/lib/Auth/ApiAuth.php on line 45 
```

The ‘ApiAuth.php’ itself is something provided by the API zip file itself. The code around line 45 says this:

```auto
public function newAuth($parameters = array(), $authMethod = 'OAuth')
    {
        $class = 'Mautic\Auth\'.$authMethod;
        $authObject = new $class();
//... and continued...
```

Seems to me that this piece code is trying to access the ‘OAuth.php’ file located in same directory, but is unable to.

I am pretty much clueless what should I do next in order to unblock this and see if I am getting correctly to mautic API. Thanks for help

---

<div class="post-metadata">

### Author: ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)
#### Post date: [December 13, 2015, 12:58pm UTC](https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955/3 "2015-12-13T12:58:47Z")

</div>

Ok, I am one more step ahead, but sill far far away from any success.  
I have added

```auto
require('OAuth.php');
```

to the function I mentioned above - and to few more places. As long as I hate playing around with API, it seems to be getting to the Mautic.

Now step two: Mautic just tells me this:

```auto
Callback is not valid.
```

I even tried to update the code above and hardcode my callback URL to the script, but still no good  
Any ideas are still appreciated

---

<div class="post-metadata">

### Author: ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)
#### Post date: [December 13, 2015, 1:04pm UTC](https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955/4 "2015-12-13T13:04:38Z")

</div>

Thank you uncle google for finding this thread:  
[https://www.mautic.org/community/index.php/525-joomla-api-callback-is-not-valid/0](https://www.mautic.org/community/index.php/525-joomla-api-callback-is-not-valid/0)

Now it seems like I need to programatically save the authorisation token 🙂

---

<div class="post-metadata">

### Author: ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)
#### Post date: [February 2, 2020, 10:56pm UTC](https://forum.mautic.org/t/cannot-access-oauth-class-from-apiauth/2955/5 "2020-02-02T22:56:30Z")

</div>


