Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specify cURL options for connections to providers #25

Open
gnadelwartz opened this issue Jul 18, 2020 · 4 comments
Open

Allow specify cURL options for connections to providers #25

gnadelwartz opened this issue Jul 18, 2020 · 4 comments

Comments

@gnadelwartz
Copy link

Hello mremi,

I must use UrlShortner with socks5 for some reasons. Unfortunately the typical shell hackers solution using proxychains shorten ... does not work with php compiled against glibc.

The solution for my own calls to cURL is to provide some cURL options:

                curl_setopt($this->handler, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
                curl_setopt($this->handler, CURLOPT_PROXY, 'localhost');

unfortunately - for me - you are using guzzle so I can't set CURLOPT direct, but luckly guzzle privides the possiblilty to pass cURL options

As UrlShortner is working with user and password on my server, I tried to add the the socks5 options to your bitly provider for shortening, but it has ho effect:

    public function shorten(LinkInterface $link, $domain = null)
    {
        $client = $this->createClient();

        $this->options['headers']['Authorization'] = 'Bearer '.$this->auth->getAccessToken();

        $response = $client->post('/v4/shorten', array_merge([
            'json' => [
                'domain'   => $domain,
                'long_url' => $link->getLongUrl(),
            ],

       'curl' => [
            CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME,
            CURLOPT_PROXY => 'localhost'
        ],

        ], $this->options));

        $response = $this->validate($response);

        $link->setShortUrl($response->link);
    }

Are I'm doing something fundamentally worng or did I miss something?

Any other ideas?

@gnadelwartz
Copy link
Author

gnadelwartz commented Jul 20, 2020

OK found the Problem, UrlShortner needs to first geht the oAuth key, so I have to add it there also:

    public function getAccessToken()
    {
        $client = new Client( [
            'base_uri' => 'https://api-ssl.bitly.com/oauth/access_token',
       'curl' => [
            CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME,
            CURLOPT_PROXY => 'localhost'
        ],
        ]);

        $response = $client->post(null, [
            'auth' => [
                $this->username,
                $this->password,
            ],
        ]);

        return $response->getBody()->getContents();
    }

@gnadelwartz gnadelwartz changed the title Use UrlShortner with socks5 ? Allow specify cURL options for connetions to rpoviders Jul 20, 2020
@gnadelwartz
Copy link
Author

Even I found a solution to my Problem, it would be nice to add the possibility to set cUrl options globaly for all modules if needed.

@gnadelwartz gnadelwartz changed the title Allow specify cURL options for connetions to rpoviders Allow specify cURL options for connetions to providers Jul 20, 2020
@gnadelwartz gnadelwartz changed the title Allow specify cURL options for connetions to providers Allow specify cURL options for connections to providers Jul 20, 2020
@mremi
Copy link
Owner

mremi commented Jul 20, 2020

Hi @gnadelwartz ,

Yes you're right, we could pass options in construct as the provider.
Could you open a PR in this way please?

@gnadelwartz
Copy link
Author

even it may not look like, I'm a noob in php programing :)

I can write simple php scripts and copy solutions from stack overflow or find simple fixes,
but if it comes to real php incl. OO I have to give up.

I'm more a Shell hacker from stone age

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants