@@ -72,6 +72,9 @@ class Client
7272 // Token string
7373 public $ token ;
7474
75+ // Authentication type: 'storage-token' (default) or 'bearer'
76+ private string $ authType = 'storage-token ' ;
77+
7578 // current run id sent with all request
7679 private $ runId = null ;
7780
@@ -136,7 +139,7 @@ class Client
136139 * ]);
137140 *
138141 * @param array $config Client configuration settings
139- * - token: (required) Storage API token
142+ * - token: (required) Storage API token or OAuth access token (without "Bearer " prefix)
140143 * - url: (required) Storage API URL
141144 * - userAgent: custom user agent
142145 * - backoffMaxTries: backoff maximum number of attempts
@@ -145,6 +148,7 @@ class Client
145148 * - logger: instance of Psr\Log\LoggerInterface
146149 * - jobPollRetryDelay: callable method which determines wait period for job polling
147150 * - handler: custom Guzzle handler, allows mocking responses in tests
151+ * - authType: authentication type, either 'storage-token' (default) or 'bearer'
148152 */
149153 public function __construct (array $ config = [])
150154 {
@@ -163,6 +167,13 @@ public function __construct(array $config = [])
163167 }
164168 $ this ->token = $ config ['token ' ];
165169
170+ if (isset ($ config ['authType ' ])) {
171+ if (!in_array ($ config ['authType ' ], ['storage-token ' , 'bearer ' ], true )) {
172+ throw new \InvalidArgumentException ('authType must be either "storage-token" or "bearer" ' );
173+ }
174+ $ this ->authType = $ config ['authType ' ];
175+ }
176+
166177 if (isset ($ config ['backoffMaxTries ' ])) {
167178 $ this ->backoffMaxTries = (int ) $ config ['backoffMaxTries ' ];
168179 }
@@ -2878,10 +2889,14 @@ protected function request($method, $url, $options = [], $responseFileName = nul
28782889 }
28792890
28802891 $ defaultHeaders = [
2881- 'X-StorageApi-Token ' => $ this ->token ,
28822892 'Accept-Encoding ' => 'gzip ' ,
28832893 'User-Agent ' => $ this ->getUserAgent (),
28842894 ];
2895+ if ($ this ->authType === 'bearer ' ) {
2896+ $ defaultHeaders ['Authorization ' ] = 'Bearer ' . $ this ->token ;
2897+ } else {
2898+ $ defaultHeaders ['X-StorageApi-Token ' ] = $ this ->token ;
2899+ }
28852900 if (isset ($ options ['headers ' ])) {
28862901 $ requestOptions ['headers ' ] = array_merge ($ options ['headers ' ], $ defaultHeaders );
28872902 } else {
0 commit comments