|
| 1 | +# Google Auth PHP Sample Application |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +This command-line application shows how to authenticate to Google Cloud APIs |
| 6 | +using different methods. This sample uses Storage as an example, but these |
| 7 | +methods will work on any Google Cloud API. |
| 8 | + |
| 9 | +## Build and Run |
| 10 | +1. **Enable APIs** - [Enable the Storage API](https://console.cloud.google.com/flows/enableapi?apiid=storage-api.googleapis.com) |
| 11 | + and create a new project or select an existing project. |
| 12 | +2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "New Credentials" |
| 13 | + and select "Service Account Key". Create a new service account, use the JSON key type, and |
| 14 | + select "Create". Once downloaded, set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` |
| 15 | + to the path of the JSON key that was downloaded. |
| 16 | +3. **Clone the repo** and cd into this directory |
| 17 | +``` |
| 18 | + $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples |
| 19 | + $ cd php-docs-samples/auth |
| 20 | +``` |
| 21 | +4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md). |
| 22 | + Run `php composer.phar install` (if composer is installed locally) or `composer install` |
| 23 | + (if composer is installed globally). |
| 24 | +5. Run `php auth.php`. The following commands are available and work on command line: |
| 25 | +``` |
| 26 | + auth-cloud-implicit Authenticate to a cloud client library using a service account implicitly. |
| 27 | + auth-cloud-explicit Authenticate to a cloud client library using a service account explicitly. |
| 28 | +``` |
| 29 | +6. The following commands are available but will throw a ServiceException when |
| 30 | +run from command-line. The Compute Engine method only works on Compute Engine, |
| 31 | +App Engine Flexible, Cloud Functions, and Container Engine. The App Engine |
| 32 | +method only works on App Engine Standard. |
| 33 | +``` |
| 34 | + auth-cloud-explicit-compute-engine Authenticate to a cloud client library using Compute Engine credentials explicitly. |
| 35 | + auth-cloud-explicit-app-engine Authenticate to a cloud client library using App Engine Standard credentials explicitly. |
| 36 | +``` |
| 37 | +7. Run `php auth.php COMMAND --help` to print information about the usage of each command. |
| 38 | + |
| 39 | +## Contributing changes |
| 40 | + |
| 41 | +* See [CONTRIBUTING.md](../../CONTRIBUTING.md) |
| 42 | + |
| 43 | +## Licensing |
| 44 | + |
| 45 | +* See [LICENSE](../../LICENSE) |
0 commit comments