Google Identity Services is migrating to FedCM APIs. Follow the migration guide to review potential changes and avoid negative impacts for user sign-in to your website.
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:
<divid="g_id_onload"data-client_id="YOUR_GOOGLE_CLIENT_ID"data-callback="handleCredentialResponse">
</div>
<script>
functionhandleCredentialResponse(response){// decodeJwtResponse() is a custom function defined by you// to decode the credential response.constresponsePayload=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);}
</script>
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["Google Identity Services allows customization of the default login flow to fit specific needs."],["Customization can be achieved using JavaScript in conjunction with the HTML API, particularly by handling the credential response with a callback function."],["Developers need to decode the JWT credential and verify the Google ID token on the server side for security."],["The `data-callback` attribute enables custom handling of user credentials, while avoiding simultaneous use with the `data-login_uri` attribute."]]],[]]