PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / google / apiclient / src / AuthHandler / Guzzle6AuthHandler.php
ameliabooking / vendor / google / apiclient / src / AuthHandler Last commit date
AuthHandlerFactory.php 6 months ago Guzzle6AuthHandler.php 6 months ago Guzzle7AuthHandler.php 6 months ago
Guzzle6AuthHandler.php
111 lines
1 <?php
2
3 namespace AmeliaVendor\Google\AuthHandler;
4
5 use AmeliaVendor\Google\Auth\CredentialsLoader;
6 use AmeliaVendor\Google\Auth\FetchAuthTokenCache;
7 use AmeliaVendor\Google\Auth\HttpHandler\HttpHandlerFactory;
8 use AmeliaVendor\Google\Auth\Middleware\AuthTokenMiddleware;
9 use AmeliaVendor\Google\Auth\Middleware\ScopedAccessTokenMiddleware;
10 use AmeliaVendor\Google\Auth\Middleware\SimpleMiddleware;
11 use AmeliaVendor\GuzzleHttp\Client;
12 use AmeliaVendor\GuzzleHttp\ClientInterface;
13 use AmeliaVendor\Psr\Cache\CacheItemPoolInterface;
14
15 /**
16 * This supports Guzzle 6
17 */
18 class Guzzle6AuthHandler
19 {
20 protected $cache;
21 protected $cacheConfig;
22
23 public function __construct(?CacheItemPoolInterface $cache = null, array $cacheConfig = [])
24 {
25 $this->cache = $cache;
26 $this->cacheConfig = $cacheConfig;
27 }
28
29 public function attachCredentials(
30 ClientInterface $http,
31 CredentialsLoader $credentials,
32 ?callable $tokenCallback = null
33 ) {
34 // use the provided cache
35 if ($this->cache) {
36 $credentials = new FetchAuthTokenCache(
37 $credentials,
38 $this->cacheConfig,
39 $this->cache
40 );
41 }
42
43 return $this->attachCredentialsCache($http, $credentials, $tokenCallback);
44 }
45
46 public function attachCredentialsCache(
47 ClientInterface $http,
48 FetchAuthTokenCache $credentials,
49 ?callable $tokenCallback = null
50 ) {
51 // if we end up needing to make an HTTP request to retrieve credentials, we
52 // can use our existing one, but we need to throw exceptions so the error
53 // bubbles up.
54 $authHttp = $this->createAuthHttp($http);
55 $authHttpHandler = HttpHandlerFactory::build($authHttp);
56 $middleware = new AuthTokenMiddleware(
57 $credentials,
58 $authHttpHandler,
59 $tokenCallback
60 );
61
62 $config = $http->getConfig();
63 $config['handler']->remove('google_auth');
64 $config['handler']->push($middleware, 'google_auth');
65 $config['auth'] = 'google_auth';
66 $http = new Client($config);
67
68 return $http;
69 }
70
71 public function attachToken(ClientInterface $http, array $token, array $scopes)
72 {
73 $tokenFunc = function ($scopes) use ($token) {
74 return $token['access_token'];
75 };
76
77 $middleware = new ScopedAccessTokenMiddleware(
78 $tokenFunc,
79 $scopes,
80 $this->cacheConfig,
81 $this->cache
82 );
83
84 $config = $http->getConfig();
85 $config['handler']->remove('google_auth');
86 $config['handler']->push($middleware, 'google_auth');
87 $config['auth'] = 'scoped';
88 $http = new Client($config);
89
90 return $http;
91 }
92
93 public function attachKey(ClientInterface $http, $key)
94 {
95 $middleware = new SimpleMiddleware(['key' => $key]);
96
97 $config = $http->getConfig();
98 $config['handler']->remove('google_auth');
99 $config['handler']->push($middleware, 'google_auth');
100 $config['auth'] = 'simple';
101 $http = new Client($config);
102
103 return $http;
104 }
105
106 private function createAuthHttp(ClientInterface $http)
107 {
108 return new Client(['http_errors' => true] + $http->getConfig());
109 }
110 }
111