@@ -61,21 +61,41 @@ public function preSend(RequestInterface $request)
6161 $ request ->addHeader ('Authorization: token ' . $ this ->options ['token ' ]);
6262 break ;
6363
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+
6483 case Client::AUTH_URL_TOKEN :
6584 if (!isset ($ this ->options ['token ' ])) {
6685 throw new InvalidArgumentException ('You need to set OAuth token! ' );
6786 }
68- $ url = $ request ->getUrl ();
6987
7088 if ('GET ' === $ request ->getMethod ()) {
89+ $ url = $ request ->getUrl ();
90+
7191 $ parameters = array (
7292 'access_token ' => $ this ->options ['token ' ]
7393 );
7494
75- $ url .= '? ' .utf8_encode (http_build_query ($ parameters , '' , '& ' ));
76- }
95+ $ url .= (false === strpos ($ url , '? ' ) ? '? ' : '& ' ).utf8_encode (http_build_query ($ parameters , '' , '& ' ));
7796
78- $ request ->fromUrl (new Url ($ url ));
97+ $ request ->fromUrl (new Url ($ url ));
98+ }
7999 break ;
80100 }
81101 }
0 commit comments