Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9752362

Browse filesBrowse files
buserpJon Wayne Parrott
authored andcommitted
Add an example for IAP on GCE (GoogleCloudPlatform#1099)
1 parent ce8fee6 commit 9752362
Copy full SHA for 9752362

File tree

Expand file treeCollapse file tree

2 files changed

+44
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-0
lines changed

‎iap/example_gce_backend.py

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import platform
16+
17+
import flask
18+
19+
import validate_jwt
20+
21+
CLOUD_PROJECT_ID = 'YOUR_PROJECT_ID'
22+
BACKEND_SERVICE_ID = 'YOUR_BACKEND_SERVICE_ID'
23+
24+
app = flask.Flask(__name__)
25+
26+
27+
@app.route('/')
28+
def root():
29+
jwt = flask.request.headers.get('x-goog-iap-jwt-assertion')
30+
if jwt is None:
31+
return 'Unauthorized request.'
32+
user_id, user_email, error_str = (
33+
validate_jwt.validate_iap_jwt_from_compute_engine(
34+
jwt, CLOUD_PROJECT_ID, BACKEND_SERVICE_ID))
35+
if error_str:
36+
return 'Error: {}'.format(error_str)
37+
else:
38+
return 'Hi, {}. I am {}.'.format(user_email, platform.node())
39+
40+
41+
if __name__ == '__main__':
42+
app.run()

‎iap/requirements.txt

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
PyJWT==1.5.3
22
cryptography==2.0.3
3+
flask==0.12.2
34
google-auth==1.1.0
5+
gunicorn==19.7.1
46
requests==2.18.4
57
requests_toolbelt==0.8.0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.