@@ -199,10 +199,9 @@ def test_api_request(request_type="username"):
199199 save_user_credentials (credentials )
200200
201201 # Render the results of the API call.
202- return flask .render_template (
203- "show-api-query-result.html" ,
204- data = json .dumps (fetched_data , indent = 2 ),
205- data_title = request_type )
202+ return flask .render_template ("show-api-query-result.html" ,
203+ data = json .dumps (fetched_data , indent = 2 ),
204+ data_title = request_type )
206205
207206
208207@app .route ("/authorize" )
@@ -213,7 +212,9 @@ def authorize():
213212
214213 # Create flow instance to manage the OAuth 2.0 Authorization Grant Flow steps.
215214 flow = google_auth_oauthlib .flow .Flow .from_client_secrets_file (
216- CLIENT_SECRETS_FILE , scopes = SCOPES )
215+ CLIENT_SECRETS_FILE ,
216+ scopes = SCOPES ,
217+ )
217218
218219 # The URI created here must exactly match one of the authorized redirect URIs
219220 # for the OAuth 2.0 client, which you configured in the API Console. If this
@@ -226,7 +227,12 @@ def authorize():
226227 # re-prompting the user for permission. Recommended for web server apps.
227228 access_type = "offline" ,
228229 # Enable incremental authorization. Recommended as a best practice.
229- include_granted_scopes = "true" )
230+ include_granted_scopes = "true" ,
231+ # The user will automatically be selected if we have the login_hint.
232+ login_hint = flask .session .get ("login_hint" ),
233+ # If we don't have login_hint, passing hd will reduce the list of
234+ # accounts in the account chooser to only those with the same domain.
235+ hd = flask .session .get ("hd" ))
230236
231237 # Store the state so the callback can verify the auth server response.
232238 flask .session ["state" ] = state
@@ -258,7 +264,7 @@ def callback():
258264 credentials = flow .credentials
259265 flask .session ["credentials" ] = credentials_to_dict (credentials )
260266
261- # The flow is complete! We'll use the credentials to fetch the username .
267+ # The flow is complete! We'll use the credentials to fetch the user's info .
262268 user_info_service = googleapiclient .discovery .build (
263269 serviceName = "oauth2" , version = "v2" , credentials = credentials )
264270
0 commit comments