Ответы пользователя по тегу Google
  • Как получить id token google api?

    @AlexVWill
    Есть же официальная документация по этому вопросу, там очень подробно и доступно все написано, как получать данные профиля, как получать токен, как его даже не бэкэнд проверять на валидность. Читал?
    https://developers.google.com/identity/gsi/web/gui...
    Ответ написан
    Комментировать
  • Как получить данные профиля после google sign in на стороне севрера?

    @AlexVWill
    Есть же целый, толковый гайд по этой функции
    https://developers.google.com/identity/gsi/web/gui...

    spoiler
    <html lang="en">
      <head>
        <meta name="google-signin-scope" content="profile email">
        <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
        <script src="https://apis.google.com/js/platform.js" async defer></script>
      </head>
      <body>
        <div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
        <script>
          function onSignIn(googleUser) {
            // Useful data for your client-side scripts:
            var profile = googleUser.getBasicProfile();
            console.log("ID: " + profile.getId()); // Don't send this directly to your server!
            console.log('Full Name: ' + profile.getName());
            console.log('Given Name: ' + profile.getGivenName());
            console.log('Family Name: ' + profile.getFamilyName());
            console.log("Image URL: " + profile.getImageUrl());
            console.log("Email: " + profile.getEmail());
    
            // The ID token you need to pass to your backend:
            var id_token = googleUser.getAuthResponse().id_token;
            console.log("ID Token: " + id_token);
          }
        </script>
      </body>
    </html>


    Если вкратце, то Google Sign In возвращает токен, в виде длинной строки символов
    который можно передать на сайт верификации
    https://oauth2.googleapis.com/tokeninfo?id_token=XYZ123
    который возвратит JSON массив с данными эккаунта
    {
     // These six fields are included in all Google ID Tokens.
     "iss": "https://accounts.google.com",
     "sub": "110169484474386276334",
     "azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
     "aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
     "iat": "1433978353",
     "exp": "1433981953",
    
     // These seven fields are only included when the user has granted the "profile" and
     // "email" OAuth scopes to the application.
     "email": "testuser@gmail.com",
     "email_verified": "true",
     "name" : "Test User",
     "picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
     "given_name": "Test",
     "family_name": "User",
     "locale": "en"
    }
    Ответ написан
    Комментировать