Skip to content

Commit 8b82a3a

Browse files
committed
Add Oauth 2 support
Grant Types are configured outside the lib and our Config object hooks its all up for easy peasy Oauth 2.
1 parent 64b8100 commit 8b82a3a

File tree

3 files changed

+100
-4
lines changed

3 files changed

+100
-4
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
"guzzlehttp/guzzle-services": "^1.1",
1616
"gimler/guzzle-description-loader": "^0.0.4"
1717
},
18-
18+
1919
"require-dev": {
2020
"symfony/css-selector": "~2.2",
2121
"symfony/dom-crawler": "~2.2",
2222
"symfony/console": "~2.2",
2323
"phpunit/phpunit": "^4.8",
2424
"symfony/var-dumper": "~2.6",
2525
"mathiasgrimm/arraypath": "~1.3",
26-
"guzzlehttp/oauth-subscriber": "^0.3.0"
26+
"guzzlehttp/oauth-subscriber": "^0.3.0",
27+
"kamermans/guzzle-oauth2-subscriber": "^1.0"
2728
},
2829
"suggest": {
29-
"guzzlehttp/oauth-subscriber": "For authenticating with Oauth1.0"
30+
"guzzlehttp/oauth-subscriber": "For authenticating with Oauth1.0",
31+
"kamermans/guzzle-oauth2-subscriber": "For authenticating with OAuth2"
3032
},
3133

3234
"autoload": {

composer.lock

Lines changed: 42 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace DMS\Service\Meetup\Config;
4+
5+
use kamermans\OAuth2\GrantType\GrantTypeInterface;
6+
use kamermans\OAuth2\OAuth2Middleware;
7+
8+
final class OAuth2Config implements ClientConfig
9+
{
10+
/**
11+
* @var GrantTypeInterface
12+
*/
13+
protected $grantType;
14+
15+
/**
16+
* @var bool
17+
*/
18+
protected $shouldSignAllRequests;
19+
20+
/**
21+
* @param GrantTypeInterface $grantType
22+
* @param bool $shouldSignAllRequests
23+
*/
24+
public function __construct(GrantTypeInterface $grantType, bool $shouldSignAllRequests = true)
25+
{
26+
$this->grantType = $grantType;
27+
$this->shouldSignAllRequests = $shouldSignAllRequests;
28+
}
29+
30+
/**
31+
* @return callable[]
32+
*/
33+
public function getMiddleware(): array
34+
{
35+
return [
36+
'oauth2' => new OAuth2Middleware($this->grantType)
37+
];
38+
}
39+
40+
/**
41+
* @return string[]
42+
*/
43+
public function getClientConfig(): array
44+
{
45+
$config = [];
46+
47+
if ($this->shouldSignAllRequests) {
48+
$config['auth'] = 'oauth';
49+
}
50+
51+
return $config;
52+
}
53+
}

0 commit comments

Comments
 (0)