Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bingo
Oauth2Client
Commits
6d987daf
Commit
6d987daf
authored
9 years ago
by
Woody Gilk
Browse files
Options
Download
Plain Diff
Merge pull request #516 from EricHogue/AllowUsingProxy
Allow using a proxy for debugging.
parents
b3242ca3
2ca9f4fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
1 deletion
+71
-1
README.md
README.md
+17
-0
src/Provider/AbstractProvider.php
src/Provider/AbstractProvider.php
+22
-1
test/src/Provider/AbstractProviderTest.php
test/src/Provider/AbstractProviderTest.php
+32
-0
No files found.
README.md
View file @
6d987daf
...
...
@@ -227,6 +227,23 @@ try {
}
```
### Using a proxy
It is possible to use a proxy to debug HTTP calls made to a provider. All you need to do is set the
`proxy`
and
`verify`
options when creating your Provider instance. Make sure you enable SSL proxying in your proxy.
```
php
$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
]);
```
## Install
Via Composer
...
...
This diff is collapsed.
Click to expand it.
src/Provider/AbstractProvider.php
View file @
6d987daf
...
...
@@ -122,7 +122,8 @@ abstract class AbstractProvider
$this
->
setRequestFactory
(
$collaborators
[
'requestFactory'
]);
if
(
empty
(
$collaborators
[
'httpClient'
]))
{
$client_options
=
[
'timeout'
];
$client_options
=
$this
->
getAllowedClientOptions
(
$options
);
$collaborators
[
'httpClient'
]
=
new
HttpClient
(
array_intersect_key
(
$options
,
array_flip
(
$client_options
))
);
...
...
@@ -135,6 +136,26 @@ abstract class AbstractProvider
$this
->
setRandomFactory
(
$collaborators
[
'randomFactory'
]);
}
/**
* Return the list of options that can be passed to the HttpClient
*
* @param array $options An array of options to set on this provider.
* Options include `clientId`, `clientSecret`, `redirectUri`, and `state`.
* Individual providers may introduce more options, as needed.
* @return array The options to pass to the HttpClient constructor
*/
protected
function
getAllowedClientOptions
(
array
$options
)
{
$client_options
=
[
'timeout'
,
'proxy'
];
// Only allow turning off ssl verification is it's for a proxy
if
(
!
empty
(
$options
[
'proxy'
]))
{
$client_options
[]
=
'verify'
;
}
return
$client_options
;
}
/**
* Sets the grant factory instance.
*
...
...
This diff is collapsed.
Click to expand it.
test/src/Provider/AbstractProviderTest.php
View file @
6d987daf
...
...
@@ -111,6 +111,38 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$timeout
,
$config
[
'timeout'
]);
}
public
function
testCanSetAProxy
()
{
$proxy
=
'192.168.0.1:8888'
;
$mockProvider
=
new
MockProvider
([
'proxy'
=>
$proxy
]);
$config
=
$mockProvider
->
getHttpClient
()
->
getConfig
();
$this
->
assertContains
(
'proxy'
,
$config
);
$this
->
assertEquals
(
$proxy
,
$config
[
'proxy'
]);
}
public
function
testCannotDisableVerifyIfNoProxy
()
{
$mockProvider
=
new
MockProvider
([
'verify'
=>
false
]);
$config
=
$mockProvider
->
getHttpClient
()
->
getConfig
();
$this
->
assertContains
(
'verify'
,
$config
);
$this
->
assertTrue
(
$config
[
'verify'
]);
}
public
function
testCanDisableVerificationIfThereIsAProxy
()
{
$mockProvider
=
new
MockProvider
([
'proxy'
=>
'192.168.0.1:8888'
,
'verify'
=>
false
]);
$config
=
$mockProvider
->
getHttpClient
()
->
getConfig
();
$this
->
assertContains
(
'verify'
,
$config
);
$this
->
assertFalse
(
$config
[
'verify'
]);
}
public
function
testConstructorSetsGrantFactory
()
{
$mockAdapter
=
m
::
mock
(
GrantFactory
::
class
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment