用Oauth2实施登录的更快方法是什么?

时间:2019-04-10 22:03:22

标签: php oauth-2.0 google-oauth

如何实现更快的oauth2?我尝试实现https://developers.google.com/identity/sign-in/web/所述的Oauth。但是,实施后,该页面的加载速度现在 27,450%变慢了!

我想发生的是,那时只有一个用于Google登录的按钮图像:

1. When a user click that button, it sends him to accounts.google.com/o/auth
2. When the user successfully log in, accounts.google.com sends to the website server the basic information
3. Then the server just parse that information using php. (Maybe using GET request, if not maybe a GET request to a token identifying the user at that moment)

这是我将页面加载速度降低超过 27,000%的代码!

<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>

编辑: 页面加载是使用Chrome DevTool确定的。

0 个答案:

没有答案