1616 * limitations under the License.
1717 */
1818
19- use GuzzleHttp \ Client ;
19+ use Google \ Auth \ HttpHandler \ HttpHandlerFactory ;
2020use GuzzleHttp \ClientInterface ;
21+ use GuzzleHttp \Psr7 ;
22+ use GuzzleHttp \Psr7 \Request ;
2123
2224/**
2325 * Wrapper around Google Access Tokens which provides convenience functions
@@ -36,10 +38,6 @@ class Google_AccessToken_Revoke
3638 */
3739 public function __construct (ClientInterface $ http = null )
3840 {
39- if (is_null ($ http )) {
40- $ http = new Client ();
41- }
42-
4341 $ this ->http = $ http ;
4442 }
4543
@@ -53,17 +51,25 @@ public function __construct(ClientInterface $http = null)
5351 public function revokeToken (array $ token )
5452 {
5553 if (isset ($ token ['refresh_token ' ])) {
56- $ tokenString = $ token ['refresh_token ' ];
54+ $ tokenString = $ token ['refresh_token ' ];
5755 } else {
58- $ tokenString = $ token ['access_token ' ];
56+ $ tokenString = $ token ['access_token ' ];
5957 }
6058
61- $ request = $ this ->http ->createRequest ('POST ' , Google_Client::OAUTH2_REVOKE_URI );
62- $ request ->addHeader ('Cache-Control ' , 'no-store ' );
63- $ request ->addHeader ('Content-Type ' , 'application/x-www-form-urlencoded ' );
64- $ request ->getBody ()->replaceFields (array ('token ' => $ tokenString ));
59+ $ body = Psr7 \stream_for (http_build_query (array ('token ' => $ tokenString )));
60+ $ request = new Request (
61+ 'POST ' ,
62+ Google_Client::OAUTH2_REVOKE_URI ,
63+ [
64+ 'Cache-Control ' => 'no-store ' ,
65+ 'Content-Type ' => 'application/x-www-form-urlencoded ' ,
66+ ],
67+ $ body
68+ );
69+
70+ $ httpHandler = HttpHandlerFactory::build ($ this ->http );
6571
66- $ response = $ this -> http -> send ($ request );
72+ $ response = $ httpHandler ($ request );
6773 if ($ response ->getStatusCode () == 200 ) {
6874 return true ;
6975 }
0 commit comments