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{access_token:string}
|
---|
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|null $httpHandler
|
---|
40 | * @return array{access_token:string} A set of auth related metadata
|
---|
41 | */
|
---|
42 | public function fetchAuthToken(?callable $httpHandler = null)
|
---|
43 | {
|
---|
44 | return $this->token;
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Returns the cache key. In this case it returns a null value, disabling
|
---|
49 | * caching.
|
---|
50 | *
|
---|
51 | * @return string|null
|
---|
52 | */
|
---|
53 | public function getCacheKey()
|
---|
54 | {
|
---|
55 | return null;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Fetches the last received token. In this case, it returns the same empty string
|
---|
60 | * auth token.
|
---|
61 | *
|
---|
62 | * @return array{access_token:string}
|
---|
63 | */
|
---|
64 | public function getLastReceivedToken()
|
---|
65 | {
|
---|
66 | return $this->token;
|
---|
67 | }
|
---|
68 | }
|
---|