16
16
* limitations under the License.
17
17
*/
18
18
19
- use GuzzleHttp \ Client ;
19
+ use Google \ Auth \ HttpHandler \ HttpHandlerFactory ;
20
20
use GuzzleHttp \ClientInterface ;
21
+ use GuzzleHttp \Psr7 ;
22
+ use GuzzleHttp \Psr7 \Request ;
21
23
22
24
/**
23
25
* Wrapper around Google Access Tokens which provides convenience functions
@@ -36,10 +38,6 @@ class Google_AccessToken_Revoke
36
38
*/
37
39
public function __construct (ClientInterface $ http = null )
38
40
{
39
- if (is_null ($ http )) {
40
- $ http = new Client ();
41
- }
42
-
43
41
$ this ->http = $ http ;
44
42
}
45
43
@@ -53,17 +51,25 @@ public function __construct(ClientInterface $http = null)
53
51
public function revokeToken (array $ token )
54
52
{
55
53
if (isset ($ token ['refresh_token ' ])) {
56
- $ tokenString = $ token ['refresh_token ' ];
54
+ $ tokenString = $ token ['refresh_token ' ];
57
55
} else {
58
- $ tokenString = $ token ['access_token ' ];
56
+ $ tokenString = $ token ['access_token ' ];
59
57
}
60
58
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 );
65
71
66
- $ response = $ this -> http -> send ($ request );
72
+ $ response = $ httpHandler ($ request );
67
73
if ($ response ->getStatusCode () == 200 ) {
68
74
return true ;
69
75
}
0 commit comments