Skip to content

Commit 636b155

Browse files
ryanmatsbshaffer
authored andcommitted
IAP code sample (GoogleCloudPlatform#459)
* First draft of IAP code sample * Validate JWT draft - not working 100% yet * Validate JWT code + tests + code review fixes * Added IAP_SERVICE_ACCOUNT to travis.yml * Removing index.php * Make Travis tests configure IAP service account * Linting fixes * More linting fixes * Using Travis service account for IAP * Added README instructions * Code review style + testing changes * Moved README tutorial links to the top; clarified where to find project number * Linting issue
1 parent f20da01 commit 636b155

File tree

8 files changed

+2374
-0
lines changed

8 files changed

+2374
-0
lines changed

iap/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Google Cloud Identity Aware Proxy Samples
2+
3+
These samples show how to use the [Google Cloud Identity Aware Proxy][iap]. Cloud Identity-Aware Proxy (Cloud IAP) controls access to your cloud applications running on Google Cloud Platform. Cloud IAP works by verifying a user’s identity and determining if that user should be allowed to access the application.
4+
5+
If this is your first time using the Google Cloud Identity Aware Proxy, try out our [quickstart tutorial][iap-quickstart].
6+
7+
Visit the [Programmatic authentication][iap-programmatic-authentication] and [Securing your app with signed headers][iap-signed-headers] tutorials to learn more about how these code samples work.
8+
9+
You can also learn more by reading the [Cloud IAP conceptual overview][iap-conceptual-overview].
10+
11+
## Setup
12+
13+
1. Deploy this [basic web application to App Engine][iap-app-engine].
14+
1. Once the application is deployed, enable Cloud IAP for it using the Enabling Cloud IAP section of [this tutorial][iap-enable].
15+
1. [Create a service account][create-service-account] that you will later use to access your Cloud IAP protected site. Give it the role of 'Project > Owner' and check the box for 'Furnish a new private key'.
16+
1. Save the service account key you created in the previous step to your local computer.
17+
1. [Grant your service account access][iap-manage-access] to your Cloud IAP application.
18+
1. Visit the [Cloud IAP admin page][iap-console] and click the ellipses button on the same row as 'App Engine app'. Click 'Edit OAuth Client' and note the Client ID.
19+
1. **Install dependencies** via [Composer][composer]. Run `php composer.phar install` (if composer is installed locally) or `composer install` (if composer is installed globally).
20+
21+
## Samples
22+
23+
To run the Cloud Identity Aware Proxy Samples:
24+
25+
$ php iap.php
26+
Cloud Identity Aware Proxy
27+
28+
Usage:
29+
command [options] [arguments]
30+
31+
Options:
32+
-h, --help Display this help message
33+
-q, --quiet Do not output any message
34+
-V, --version Display this application version
35+
--ansi Force ANSI output
36+
--no-ansi Disable ANSI output
37+
-n, --no-interaction Do not ask any interactive question
38+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
39+
40+
Available commands:
41+
request Make a request to an IAP-protected resource using a service account.
42+
validate Make a request to an IAP-protected resource using a service account and then validate the JWT.
43+
44+
### Run Request
45+
46+
To run the Request sample:
47+
48+
$ php iap.php request [YOUR_CLOUD_IAP_URL] [YOUR_CLIENT_ID] [PATH_TO_YOUR_SERVICE_ACCOUNT]
49+
50+
### Run Validate
51+
52+
To run the Analyze Sentiment sample:
53+
54+
$ php iap.php validate [YOUR_CLOUD_IAP_URL] [YOUR_CLIENT_ID] [PATH_TO_YOUR_SERVICE_ACCOUNT] [YOUR_PROJECT_NUMBER] [YOUR_PROJECT_ID]
55+
56+
[iap]: http://cloud.google.com/iap
57+
[iap-quickstart]: https://cloud.google.com/iap/docs/app-engine-quickstart
58+
[iap-app-engine]: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/iap/app_engine_app
59+
[iap-enable]: https://cloud.google.com/iap/docs/app-engine-quickstart#enabling_iap
60+
[create-service-account]: https://console.cloud.google.com/iam-admin/serviceaccounts?_ga=2.249998854.-1228762175.1480648951
61+
[iap-manage-access]: https://cloud.google.com/iap/docs/managing-access
62+
[iap-console]: https://console.cloud.google.com/iam-admin/iap
63+
[composer]: http://getcomposer.org/doc/00-intro.md
64+
[iap-programmatic-authentication]: https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_a_service_account
65+
[iap-signed-headers]: https://cloud.google.com/iap/docs/signed-headers-howto
66+
[iap-conceptual-overview]: https://cloud.google.com/iap/docs/concepts-overview

iap/composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"require": {
3+
"symfony/console": "^2.8",
4+
"google/auth":"dev-additional-claims as v1.0.1",
5+
"lcobucci/jwt": "^3.2",
6+
"mdanter/ecc":"0.3.2"
7+
},
8+
"autoload": {
9+
"psr-4": {
10+
"Google\\Cloud\\Samples\\Auth\\": "src/"
11+
},
12+
"files": [
13+
"src/make_iap_request.php",
14+
"src/validate_jwt.php"
15+
]
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "~4"
19+
}
20+
}

0 commit comments

Comments
 (0)