arrow_back
Back

Google Sign-In: Client ID, profile callback, and ID token verification

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Documentation:

How it works

For each site you create an application with its own Client ID. The frontend asks the user for authorization; after they approve, your callback runs:

function onSignIn(googleUser) {
  var profile = googleUser.getBasicProfile();
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail()); // null if the email scope is missing
}

Do not POST those profile fields to your backend over AJAX — they are easy to forge.

Send the ID token instead. On the server, verify it (e.g. with verifyIdToken) and only then trust the identity claims.

Important

verifyIdToken depends on correct server time. If the clock is wrong, verification fails.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Google Maps JavaScript API: map, markers, circles, and geocoding

arrow_forward