Skip to content

Commit a32c738

Browse files
committed
Update HTML templates to indicate that we're calling a Google API, not a Classroom API and correct the routing. Fix OAuth URL to include login_hint and hd.
Change-Id: I8caf9e5593d736d9d33e836bb9d2e4b22c795f5f
1 parent b1a7707 commit a32c738

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

flask/02-sign-in/templates/addon-discovery.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h3>Welcome to the home page!</h3>
3030
From here you can:
3131
<ul>
3232
<li>
33-
<a href="{{url_for('test_api_request', request_type='courses')}}">Test a Classroom API request</a>
33+
<a href="{{url_for('test_api_request', request_type='username')}}">Test a Google API request</a>
3434
<br>This will submit an API request and display a JSON response.
3535
<br>You should go through the authorization flow if there are no stored credentials.</li>
3636
<li><a href="{{ url_for('revoke') }}">Revoke credentials</a>

flask/03-query-parameters/main.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

flask/03-query-parameters/templates/addon-discovery.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h3>Welcome to the home page!</h3>
3030
From here you can:
3131
<ul>
3232
<li>
33-
<a href="{{url_for('test_api_request', request_type='courses')}}">Test a Classroom API request</a>
33+
<a href="{{url_for('test_api_request', request_type='username')}}">Test a Google API request</a>
3434
<br>This will submit an API request and display a JSON response.
3535
<br>You should go through the authorization flow if there are no stored credentials.</li>
3636
<li><a href="{{ url_for('revoke') }}">Revoke credentials</a>

0 commit comments

Comments
 (0)