0

Currently I'm using the Google Sign-In (Legacy) in one of my asp.net apps.

I'm trying to migrate over to the Sign In With Google button since the legacy will be discontinued in 2023.

I can get everything to work except for the below function. I need to grab some profile info for the asp.net app using the new Sign In With Google api.

    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()); // This is null if the 'email' scope is not present.
}

any help would be appreciated

user16652126
  • 41
  • 1
  • 4

1 Answers1

0

User profile information is in the base-64 encoded JWT returned to your callback in the credential field of the CredentialResponse object. The previous link has a list of fields and meanings. You may find jwt.io a help during prototyping, paste the returned ID token credential value to decode.

bdid
  • 485
  • 2
  • 6
  • Thanks....I read through that but cannot figure out how to write the java script function like I posted. I need to grab the users email address once the user signs in through google. – user16652126 Aug 12 '21 at 20:17
  • For testing, [How to decode jwt token in javascript without using a library?](https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript-without-using-a-library) might help. At that point normal [JSON Syntax](https://www.w3schools.com/js/js_json_syntax.asp) rules apply... so something like`decoded_token.email` will get you what you're after. You'll want to consider how to securely decode and verify the ID token in production, perhaps on your back-end platform. – bdid Aug 12 '21 at 21:12