I'm trying to implement a "Sign in with Google" button, as documented here: https://developers.google.com/identity/gsi/web/guides/display-button
I'm confused by what it expects for data-login_uri as illustrated below (taken from the documentation linked above):
<div id="g_id_onload"
data-client_id="YOUR_GOOGLE_CLIENT_ID"
data-login_uri="https://your.domain/your_login_endpoint"
data-auto_prompt="false">
</div>
I have my app's client ID properly configured, and I can make it through most of the sign-in/auth flow provided by Google's pop-up window. However, once the pop-up window closes, it tries to POST to whatever URI I specify as the data-login_uri.
This leads me to believe that we need a back-end endpoint to do... something... but I can't track down any documentation regarding how this endpoint is supposed to behave, and as such I'm not sure what requirements to communicate to my back-end devs.
What did I miss?
TL;DR You need a backend process (scripted in PHP, Python, Node, etc.) on your server which can relay a token_id (received from the
divyou quoted) to Google for validation.Why?
Google's documentation says:
Details
The value of the
data-auto_promptparameter should point to an endpoint of an API or an executable CGI process in the back end.Let's say your domain name is 'example.com'. There needs to be an endpoint, or executable cgi script at that endpoint that is capable of capturing a POST request, with
application/x-www-form-urlencodedencoding. It might be something like this: https://www.example.com/login.At this endpoint, a script / route should be capable of extracting the 'tokenid'
Google's documentation describes what the back end must do in two places:
Verify the Google ID token on your server side:
Here's a python code fragment for a 'login' route, using the Flask framework: (A virtual environment is recommended and a pip install of two google api's are required.)
At the command line: pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib