4
4
namespace Jeylabs \OAuth2 \Client \Provider ;
5
5
6
6
7
+ use InvalidArgumentException ;
7
8
use League \OAuth2 \Client \Provider \AbstractProvider ;
8
9
use League \OAuth2 \Client \Provider \Exception \IdentityProviderException ;
9
10
use League \OAuth2 \Client \Token \AccessToken ;
10
11
use League \OAuth2 \Client \Tool \BearerAuthorizationTrait ;
11
- use League \OAuth2 \Client \Grant \AbstractGrant ;
12
12
use Psr \Http \Message \ResponseInterface ;
13
13
14
14
class G2MProvider extends AbstractProvider
@@ -65,6 +65,57 @@ class G2MProvider extends AbstractProvider
65
65
*/
66
66
private $ responseResourceOwnerId = 'account_key ' ;
67
67
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
+
68
119
protected function checkResponse (ResponseInterface $ response , $ data )
69
120
{
70
121
if (!empty ($ data [$ this ->responseError ])) {
@@ -98,4 +149,11 @@ public function getDefaultScopes()
98
149
{
99
150
return $ this ->scopes ;
100
151
}
152
+
153
+ protected function getDefaultHeaders ()
154
+ {
155
+ return [
156
+ 'Authorization ' => 'Basic ' . base64_encode ($ this ->clientId . ': ' . $ this ->clientSecret ),
157
+ ];
158
+ }
101
159
}
0 commit comments