Warning: This data is provided under the Google User Data Policy. Please review and comply with the policy. Failure to do so might result in project or account suspension.

Handle credential responses with JavaScript functions

Stay organized with collections Save and categorize content based on your preferences.

Handle credential response

You can set a JavaScript function in the data-callback attribute to handle the returned credential response. See the following code snippet:

<div id="g_id_onload"
  function handleCredentialResponse(response) {
     // decodeJwtResponse() is a custom function defined by you
     // to decode the credential response.
     const responsePayload = decodeJwtResponse(response.credential);

     console.log("ID: " + responsePayload.sub);
     console.log('Full Name: ' + responsePayload.name);
     console.log('Given Name: ' + responsePayload.given_name);
     console.log('Family Name: ' + responsePayload.family_name);
     console.log("Image URL: " + responsePayload.picture);
     console.log("Email: " + responsePayload.email);

You can validate and decode the JWT credential by using a JWT-decoding library for your language