I am successfully creating and using a JSON Web Token based on the documentation available at https://developers.google.com/identity/gsi/web/guides/overview.
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload"
data-client_id="myclientid"
data-login_uri="mysiteurl"
data-auto_select="true">
</div>
<div class="g_id_signin"
data-type="filled_blue"
data-size="large"
data-theme="outline"
data-text="sign_in_with"
data-shape="pill"
data-logo_alignment="left">
</div>
</body>
</html>
For each call from the web client to a cloud function, I am using this Go code to confirm the token is still valid:
"google.golang.org/api/idtoken"
func ListItems(w http.ResponseWriter, r *http.Request) {
var googleClientId = os.Getenv("GOOGLE_CLIENTID")
r.ParseForm()
token := r.Form.Get("credential")
payload, err := idtoken.Validate(context.Background(), token, googleClientId)
However, the id token expires after 1 hour (3600 seconds) and there seems to be no way to create it with a longer duration.
I want the user authentication to have a duration of 8 hours. What is the best way to continue the session for the user without making them authenticate again?
Note: This documentation (https://cloud.google.com/docs/authentication/token-types#refresh) states "When your application first authenticates, it receives an access token or ID token, as well as a refresh token". Does the GSI approach actually generate a refresh token? If so, how do I get the refresh token in the cloud function?