File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Original file line number Diff line number Diff line change
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 ()
Original file line number Diff line number Diff line change 1
1
PyJWT == 1.5.3
2
2
cryptography == 2.0.3
3
+ flask == 0.12.2
3
4
google-auth == 1.1.0
5
+ gunicorn == 19.7.1
4
6
requests == 2.18.4
5
7
requests_toolbelt == 0.8.0
You can’t perform that action at this time.
0 commit comments