| 1 |
<?php |
| 2 |
/* |
| 3 |
* Copyright 2018 Google Inc. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
|
| 18 |
namespace Google\Auth\Credentials; |
| 19 |
|
| 20 |
use Google\Auth\FetchAuthTokenInterface; |
| 21 |
|
| 22 |
/** |
| 23 |
* Provides a set of credentials that will always return an empty access token. |
| 24 |
* This is useful for APIs which do not require authentication, for local |
| 25 |
* service emulators, and for testing. |
| 26 |
*/ |
| 27 |
class InsecureCredentials implements FetchAuthTokenInterface |
| 28 |
{ |
| 29 |
/** |
| 30 |
* @var array |
| 31 |
*/ |
| 32 |
private $token = [ |
| 33 |
'access_token' => '' |
| 34 |
]; |
| 35 |
|
| 36 |
/** |
| 37 |
* Fetches the auth token. In this case it returns an empty string. |
| 38 |
* |
| 39 |
* @param callable $httpHandler |
| 40 |
* @return array A set of auth related metadata, containing the following |
| 41 |
* keys: |
| 42 |
* - access_token (string) |
| 43 |
*/ |
| 44 |
public function fetchAuthToken(callable $httpHandler = null) |
| 45 |
{ |
| 46 |
return $this->token; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the cache key. In this case it returns a null value, disabling |
| 51 |
* caching. |
| 52 |
* |
| 53 |
* @return string|null |
| 54 |
*/ |
| 55 |
public function getCacheKey() |
| 56 |
{ |
| 57 |
return null; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Fetches the last received token. In this case, it returns the same empty string |
| 62 |
* auth token. |
| 63 |
* |
| 64 |
* @return array |
| 65 |
*/ |
| 66 |
public function getLastReceivedToken() |
| 67 |
{ |
| 68 |
return $this->token; |
| 69 |
} |
| 70 |
} |
| 71 |
|