Skip to content

Instantly share code, notes, and snippets.

@salrashid123
Created February 8, 2022 12:15
Show Gist options
  • Save salrashid123/0e8e5f972d616bcf02439eb509c2b22c to your computer and use it in GitHub Desktop.
Save salrashid123/0e8e5f972d616bcf02439eb509c2b22c to your computer and use it in GitHub Desktop.
GCP container image that prints details of the access_token
import os
from flask import Flask
import google.auth
from google.auth.transport.requests import AuthorizedSession
from google.auth import impersonated_credentials
from google.auth import compute_engine
app = Flask(__name__)
@app.route("/")
def hello_world():
credentials, project = google.auth.default(scopes=['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/drive'])
authed_session = AuthorizedSession(credentials)
response = authed_session.get("https://www.googleapis.com/oauth2/v3/tokeninfo")
return response.json(), 200, {'Content-Type': 'application/json'}
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
@salrashid123
Copy link
Author

Flask==2.0.2
gunicorn==20.1.0
google-auth
requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment