Skip to content

Commit 5af9c96

Browse files
Auth header added
1 parent cbe885a commit 5af9c96

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

src/Provider/G2MProvider.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
namespace Jeylabs\OAuth2\Client\Provider;
55

66

7+
use InvalidArgumentException;
78
use League\OAuth2\Client\Provider\AbstractProvider;
89
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
910
use League\OAuth2\Client\Token\AccessToken;
1011
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
11-
use League\OAuth2\Client\Grant\AbstractGrant;
1212
use Psr\Http\Message\ResponseInterface;
1313

1414
class G2MProvider extends AbstractProvider
@@ -65,6 +65,57 @@ class G2MProvider extends AbstractProvider
6565
*/
6666
private $responseResourceOwnerId = 'account_key';
6767

68+
public function __construct(array $options = [], array $collaborators = [])
69+
{
70+
$this->assertRequiredOptions($options);
71+
72+
$possible = $this->getConfigurableOptions();
73+
$configured = array_intersect_key($options, array_flip($possible));
74+
75+
foreach ($configured as $key => $value) {
76+
$this->$key = $value;
77+
}
78+
79+
// Remove all options that are only used locally
80+
$options = array_diff_key($options, $configured);
81+
82+
parent::__construct($options, $collaborators);
83+
84+
}
85+
86+
private function assertRequiredOptions(array $options)
87+
{
88+
$missing = array_diff_key(array_flip($this->getRequiredOptions()), $options);
89+
90+
if (!empty($missing)) {
91+
throw new InvalidArgumentException(
92+
'Required options not defined: ' . implode(', ', array_keys($missing))
93+
);
94+
}
95+
}
96+
97+
protected function getConfigurableOptions()
98+
{
99+
return array_merge($this->getRequiredOptions(), [
100+
'accessTokenMethod',
101+
'accessTokenResourceOwnerId',
102+
'scopeSeparator',
103+
'responseError',
104+
'responseCode',
105+
'responseResourceOwnerId',
106+
'scopes',
107+
]);
108+
}
109+
110+
protected function getRequiredOptions()
111+
{
112+
return [
113+
'urlAuthorize',
114+
'urlAccessToken',
115+
'urlResourceOwnerDetails',
116+
];
117+
}
118+
68119
protected function checkResponse(ResponseInterface $response, $data)
69120
{
70121
if (!empty($data[$this->responseError])) {
@@ -98,4 +149,11 @@ public function getDefaultScopes()
98149
{
99150
return $this->scopes;
100151
}
152+
153+
protected function getDefaultHeaders()
154+
{
155+
return [
156+
'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret),
157+
];
158+
}
101159
}

0 commit comments

Comments
 (0)