|
| 1 | +Authentication |
| 2 | +============== |
| 3 | + |
| 4 | +The client does not automatically authenticate against the API when it is |
| 5 | +instantiated - it waits for an API call. When this happens, it checks |
| 6 | +whether the current “token” has expired, and (re-)authenticates if |
| 7 | +necessary. |
| 8 | + |
| 9 | +You can force authentication, by calling: |
| 10 | + |
| 11 | +.. code-block:: php |
| 12 | +
|
| 13 | + $client->authenticate(); |
| 14 | +
|
| 15 | +If the credentials are incorrect, a ``401`` error will be returned. If |
| 16 | +credentials are correct, a ``200`` status is returned with your Service |
| 17 | +Catalog. |
| 18 | + |
| 19 | + |
| 20 | +Service Catalog |
| 21 | +--------------- |
| 22 | + |
| 23 | +The Service Catalog is returned on successful authentication, and is |
| 24 | +composed of all the different API services available to the current |
| 25 | +tenant. All of this functionality is encapsulated in the ``Catalog`` |
| 26 | +object, which allows you greater control and interactivity. |
| 27 | + |
| 28 | +.. code-block:: php |
| 29 | +
|
| 30 | + /** @var OpenCloud\Common\Service\Catalog */ |
| 31 | + $catalog = $client->getCatalog(); |
| 32 | +
|
| 33 | + // Return a list of OpenCloud\Common\Service\CatalogItem objects |
| 34 | + foreach ($catalog->getItems() as $catalogItem) { |
| 35 | +
|
| 36 | + $name = $catalogItem->getName(); |
| 37 | + $type = $catalogItem->getType(); |
| 38 | +
|
| 39 | + if ($name == 'cloudServersOpenStack' && $type == 'compute') { |
| 40 | + break; |
| 41 | + } |
| 42 | +
|
| 43 | + // Array of OpenCloud\Common\Service\Endpoint objects |
| 44 | + $endpoints = $catalogItem->getEndpoints(); |
| 45 | + foreach ($endpoints as $endpoint) { |
| 46 | + if ($endpoint->getRegion() == 'DFW') { |
| 47 | + echo $endpoint->getPublicUrl(); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | +
|
| 52 | +As you can see, you have access to each Service’s name, type and list of |
| 53 | +endpoints. Each endpoint provides access to the specific region, along |
| 54 | +with its public and private endpoint URLs. |
0 commit comments