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

extend provider options with httpClientConfig key #771

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sandacn
Copy link

@sandacn sandacn commented Mar 2, 2019

We can pass options such as timeout proxy to Provider in options, such as

$provider = new \League\OAuth2\Client\Provider\GenericProvider([
    'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
    'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
    'redirectUri'             => 'http://my.example.com/your-redirect-url/',
    'urlAuthorize'            => 'http://service.example.com/authorize',
    'urlAccessToken'          => 'http://service.example.com/token',
    'urlResourceOwnerDetails' => 'http://service.example.com/resource',
    'proxy'                   => '192.168.0.1:8888',
    'verify'                  => false
]);

But it is not extensible when need to pass more http client config parameters.
I made a change which add special key for this situation.

$provider = new \League\OAuth2\Client\Provider\GenericProvider([
    'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
    'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
    'redirectUri'             => 'http://my.example.com/your-redirect-url/',
    'urlAuthorize'            => 'http://service.example.com/authorize',
    'urlAccessToken'          => 'http://service.example.com/token',
    'urlResourceOwnerDetails' => 'http://service.example.com/resource',
    'httpClientConfig' => [
        'proxy'                   => '192.168.0.1:8888',
        'verify'                  => false
    ],
]);

This becomes more clear and extensible.

The key name: httpClientConfig, use the guzzle 's client construct parameter, the name is config.
So the key name: httpClientConfig.

If user use the httpClientConfig for option, the option will be override by the httpClientConfig. In test cases, these is a case for this:

        $configTimeout = 20;
        $optionsTimeout = 10;
        $httpClientConfig = [
            'timeout' => $configTimeout,
        ];
        $options = [
            'timeout' => $optionsTimeout,
            'httpClientConfig' => $httpClientConfig,
        ];
        $mockProvider = new MockProvider($options);

        $config = $mockProvider->getHttpClient()->getConfig();

        $this->assertContains('timeout', $config);
        $this->assertEquals($configTimeout, $config['timeout']);

Finally this patch is compatible with previous version.

Thanks.

@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #771 (1f5dcb6) into master (77def43) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##              master      #771   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       180       182    +2     
===========================================
  Files             20        20           
  Lines            464       466    +2     
===========================================
+ Hits             464       466    +2     
Impacted Files Coverage Δ
src/Provider/AbstractProvider.php 100.00% <100.00%> (ø)
src/Tool/RequestFactory.php 100.00% <0.00%> (ø)

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

Successfully merging this pull request may close these issues.

2 participants