PluginProbe
WP-Stateless – Google Cloud Storage / 3.0.3
WP-Stateless – Google Cloud Storage v3.0.3
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / Google / src / Google / AccessToken / Revoke.php

Revoke.php in WP-Stateless – Google Cloud Storage 3.0.3, at lib/Google/src/Google/AccessToken/Revoke.php

80 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Copyright 2008 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 namespace wpCloud\StatelessMedia\Google_Client;
19
20 use Google\Auth\HttpHandler\HttpHandlerFactory;
21 use GuzzleHttp\ClientInterface;
22 use GuzzleHttp\Psr7;
23 use GuzzleHttp\Psr7\Request;
24
25 /**
26 * Wrapper around Google Access Tokens which provides convenience functions
27 *
28 */
29 class Google_AccessToken_Revoke
30 {
31 /**
32 * @var \GuzzleHttp\ClientInterface The http client
33 */
34 private $http;
35
36 /**
37 * Instantiates the class, but does not initiate the login flow, leaving it
38 * to the discretion of the caller.
39 */
40 public function __construct(ClientInterface $http = null)
41 {
42 $this->http = $http;
43 }
44
45 /**
46 * Revoke an OAuth2 access token or refresh token. This method will revoke the current access
47 * token, if a token isn't provided.
48 *
49 * @param string|array $token The token (access token or a refresh token) that should be revoked.
50 * @return boolean Returns True if the revocation was successful, otherwise False.
51 */
52 public function revokeToken($token)
53 {
54 if (is_array($token)) {
55 if (isset($token['refresh_token'])) {
56 $token = $token['refresh_token'];
57 } else {
58 $token = $token['access_token'];
59 }
60 }
61
62 $body = Psr7\stream_for(http_build_query(array('token' => $token)));
63 $request = new Request(
64 'POST',
65 Google_Client::OAUTH2_REVOKE_URI,
66 [
67 'Cache-Control' => 'no-store',
68 'Content-Type' => 'application/x-www-form-urlencoded',
69 ],
70 $body
71 );
72
73 $httpHandler = HttpHandlerFactory::build($this->http);
74
75 $response = $httpHandler($request);
76
77 return $response->getStatusCode() == 200;
78 }
79 }
80