Skip to content

Commit 8622102

Browse files
use fetch_id_token
1 parent a5621d9 commit 8622102

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import requests
1818

1919
import google.auth.transport.requests
20-
import google.auth.compute_engine
20+
from google.oauth2 import id_token
2121

2222

2323
# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
@@ -32,15 +32,12 @@
3232
@app.route("/")
3333
def hello():
3434
"""Return a friendly HTTP greeting."""
35-
credentials = google.auth.compute_engine.IDTokenCredentials(
36-
http_request, "target_audience", use_metadata_identity_endpoint=True
37-
)
3835
try:
39-
credentials.refresh(http_request)
36+
token = id_token.fetch_id_token(http_request, "https://pubsub.googleapis.com")
4037
except Exception as e:
4138
return str(e)
4239
#return credentials.token
43-
return "hello world"
40+
return token
4441

4542

4643
if __name__ == "__main__":

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==1.1.1
22
requests
3-
git+https://github.com/googleapis/google-auth-library-python.git#egg=google_auth
3+
git+https://github.com/googleapis/google-auth-library-python.git@665a831dc88c034b09accdc4576a1f1f74cda509#egg=google_auth

0 commit comments

Comments
 (0)