The Test Plan doc for Google Classroom Add-ons says
■ If you receive the login_hint query parameter, you must display a Google-branded sign-in button if the login_hint query parameter does not match the currently signed in user’s ID in Classroom.
This makes sense, but I don't understand how you get the currently signed in user's ID in Classroom. The Python code in walkthrough 3 doesn't seem to do this, unless I'm missing something.
What's the proper way to get the currently signed in user's ID so I can make this comparison with login_hint?
You can fetch the user's ID with the userinfo
service. Something like:
user_info_service = googleapiclient.discovery.build(
serviceName="oauth2", version="v2", credentials=credentials)
user_info = user_info_service.userinfo().get().execute()
id = user_info.get("id")
This is done in the walkthrough, but perhaps not following that wording exactly. See the stored credentials section. I think rather than checking if the IDs match, the example app flow is more like this:
userinfo
service to get the user's ID, name, picture, whatever you need.Now later on another visit...
login_hint
because this user has signed in before.This achieves the same goal, which is ensuring the user coming from Classroom is the one that ends up signed into the add-on, even if you didn't explicitly check for the ID's matching.
The key concepts with add-ons is that:
You want to avoid the scenario where the add-on opens up for Sally in Classroom, but Timmy was already signed into your app because he was using the browser earlier, and now there's a mix up.