<p>EDIT:</p>

<p>Had to do a sudo pecl install oauth in order to get access to the right OAuth. Had to add the extension to my php.ini and restart my server.</p>

<pre><code>public function apiCall($consumer_key, $consumer_secret, $token, $token_secret, $baseURL) {
    try {

        $oauth = new \OAuth($consumer_key, $consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
        $oauth-&gt;setToken($token,$token_secret);

        $oauth-&gt;fetch($baseURL);

        $response_info = $oauth-&gt;getLastResponseInfo();
        return $oauth-&gt;getLastResponse();

    } catch(OAuthException $E) {

        echo "Exception caught!\n";
        echo "Response: ". $E-&gt;lastResponse . "\n";

    }
}
</code></pre>

<p>And lastly had to execute the above function in order to get the data I asked for.</p>

CC BY-SA 4.0
2018-10-23T13:15:06.530Z
2018-10-23T13:15:06.530Z
Stef Dg
<p>The easiest way around this is to include the required library in your main-project <code>composer.json</code> and let it handle it rather than your modules <code>composer.json</code>. </p>

<p>The alternative is to require your module properly in your main composer file as you do with plugins and install it via path which kinda breaks the idea of it</p>

CC BY-SA 4.0
2018-10-23T11:28:51.047Z
Alright but when I remove my composer data from my module itself, and install the plugin in my main folder I still can't access the required php plugin. It keeps returning tha same error. (class not found)
Stef Dg
CC BY-SA 4.0
2018-10-23T11:37:28.877Z
Full error text:
"Class 'modules\sha1hashingmodule\variables\OAuth1' not found"
Stef Dg
CC BY-SA 4.0
2018-10-23T12:45:09.677Z
Because there is no such a class in the package
Robin Schambach
CC BY-SA 4.0
2018-10-23T12:47:36.207Z
Indeed, seems it was a mistake on my end. I have to install it trough PECL.
Stef Dg
CC BY-SA 4.0
2018-10-23T12:48:34.450Z
No you just need to install it via Composer and use the correct classes
Robin Schambach
CC BY-SA 4.0
2018-10-23T12:50:36.867Z
Yes, but apparently they actually want me to have the oauth pecl extension activated.
Stef Dg
CC BY-SA 4.0
2018-10-23T10:36:27.113Z
2018-10-23T10:36:27.113Z
Robin Schambach
<p>After some research surrounding this I can't seem to fix this issue. So for a project I made a simple module with some variables that simply has to make an OAuth1 call and return some data.</p>

<p>The provider of the website advised me to use :</p>

<p><a href="https://github.com/thephpleague/oauth1-client" rel="nofollow noreferrer">https://github.com/thephpleague/oauth1-client</a></p>

<p>So in my module I initialised another composer.json and required the package above. It gets correctly installed to the vendor map in my module. However whenever I call the new OAuth() or new OAuth1() it can't be found.</p>

<p>I've tried adding it while using the packagepath in the top of my module.php as well as my moduleVariable.php but to no avail. I was wondering if I'm doing something wrong? Or forgetting something? What's the best way to add composer libraries to your own custom module?</p>

<p>Best regards!</p>

<plugins><php><composer><authentication><modules>
Craft CMS module composer dependancy
# Craft CMS module composer dependancy

(Asked by: username_0 on 2018-10-23)

After some research surrounding this I can't seem to fix this issue. So for a project I made a simple module with some variables that simply has to make an OAuth1 call and return some data.

The provider of the website advised me to use :

<https://github.com/thephpleague/oauth1-client>

So in my module I initialised another composer.json and required the package above. It gets correctly installed to the vendor map in my module. However whenever I call the new OAuth() or new OAuth1() it can't be found.

I've tried adding it while using the packagepath in the top of my module.php as well as my moduleVariable.php but to no avail. I was wondering if I'm doing something wrong? Or forgetting something? What's the best way to add composer libraries to your own custom module?

Best regards!

**Tags:** plugins, php, composer, authentication, modules

---

## 2 answers

### Answer by username_0 on 2018-10-23. Score: 1 | Accepted answer

EDIT:
Had to do a sudo pecl install oauth in order to get access to the right OAuth. Had to add the extension to my php.ini and restart my server.
public function apiCall($consumer_key, $consumer_secret, $token, $token_secret, $baseURL) {
    try {

        $oauth = new \OAuth($consumer_key, $consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
        $oauth->setToken($token,$token_secret);

        $oauth->fetch($baseURL);

        $response_info = $oauth->getLastResponseInfo();
        return $oauth->getLastResponse();

    } catch(OAuthException $E) {

        echo "Exception caught!\n";
        echo "Response: ". $E->lastResponse . "\n";

    }
}

And lastly had to execute the above function in order to get the data I asked for.


---

### Answer by username_1 on 2018-10-23. Score: 1

The easiest way around this is to include the required library in your main-project `composer.json` and let it handle it rather than your modules `composer.json`.

The alternative is to require your module properly in your main composer file as you do with plugins and install it via path which kinda breaks the idea of it

> **Comments:**
> **username_0**: Alright but when I remove my composer data from my module itself, and install the plugin in my main folder I still can't access the required php plugin. It keeps returning tha same error. (class not found)  
> **username_0**: Full error text: "Class 'modules\sha1hashingmodule\variables\OAuth1' not found"  
> **username_1**: Because there is no such a class in the package  
> **username_0**: Indeed, seems it was a mistake on my end. I have to install it trough PECL.  
> **username_1**: No you just need to install it via Composer and use the correct classes  
> **username_0**: Yes, but apparently they actually want me to have the oauth pecl extension activated.  

---

