@@ -61,21 +61,41 @@ public function preSend(RequestInterface $request)
61
61
$ request ->addHeader ('Authorization: token ' . $ this ->options ['token ' ]);
62
62
break ;
63
63
64
+ case Client::AUTH_URL_CLIENT_ID :
65
+ if (!isset ($ this ->options ['login ' ], $ this ->options ['password ' ])) {
66
+ throw new InvalidArgumentException ('You need to set client_id and client_secret! ' );
67
+ }
68
+
69
+ if ('GET ' === $ request ->getMethod ()) {
70
+ $ url = $ request ->getUrl ();
71
+
72
+ $ parameters = array (
73
+ 'client_id ' => $ this ->options ['login ' ],
74
+ 'client_secret ' => $ this ->options ['password ' ],
75
+ );
76
+
77
+ $ url .= (false === strpos ($ url , '? ' ) ? '? ' : '& ' ).utf8_encode (http_build_query ($ parameters , '' , '& ' ));
78
+
79
+ $ request ->fromUrl (new Url ($ url ));
80
+ }
81
+ break ;
82
+
64
83
case Client::AUTH_URL_TOKEN :
65
84
if (!isset ($ this ->options ['token ' ])) {
66
85
throw new InvalidArgumentException ('You need to set OAuth token! ' );
67
86
}
68
- $ url = $ request ->getUrl ();
69
87
70
88
if ('GET ' === $ request ->getMethod ()) {
89
+ $ url = $ request ->getUrl ();
90
+
71
91
$ parameters = array (
72
92
'access_token ' => $ this ->options ['token ' ]
73
93
);
74
94
75
- $ url .= '? ' .utf8_encode (http_build_query ($ parameters , '' , '& ' ));
76
- }
95
+ $ url .= (false === strpos ($ url , '? ' ) ? '? ' : '& ' ).utf8_encode (http_build_query ($ parameters , '' , '& ' ));
77
96
78
- $ request ->fromUrl (new Url ($ url ));
97
+ $ request ->fromUrl (new Url ($ url ));
98
+ }
79
99
break ;
80
100
}
81
101
}
0 commit comments