in dialogflow-cx/vpc-sc-auth-server/server/app.py [0:0]
def login_get():
"""login_get
Handles requests made to the path /login. This may occur due to a user
following a link, or other website pages redirecting here.
The request may include a query parameter called return_to, which will lead
to the user being directed to that path following a successful login. This
path is relative to the application's root URL and special characters must
be url-encoded.
Example:
GET /login?return_to=/
"""
state = request.args["state"]
# Link to redirect to Google auth service, including required query parameters.
sign_in_url = "https://accounts.google.com/o/oauth2/v2/auth?"
# Client apps and their callbacks must be registered and supplied here
sign_in_url += f"redirect_uri={get_redirect_url()}&"
sign_in_url += f'client_id={os.getenv("CLIENT_ID")}&'
# Asking for user email and any previously granted scopes openid%20email
sign_in_url += "scope=openid%20"
sign_in_url += "email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&"
sign_in_url += "include_granted_scopes=true&"
# The next two parameters are essential to get a refresh token
sign_in_url += "prompt=consent&"
sign_in_url += "access_type=offline&"
# Asking for a code that can then be exchanged for user information
sign_in_url += "response_type=code&"
# Remember this info and echo it back to me so I'll know what to do next
sign_in_url += f"state={state}&"
return redirect(sign_in_url)