如何坚持谷歌oauth登录?

时间:2016-08-31 11:47:10

标签: javascript jquery oauth

我已经在我的网站上实施了google oauth sing-in,问题是在用户被重定向到新页面后我不知道如何处理登录,

这是我如何实现按钮的代码。

<div class="Sign_in_Div">
        <div class="gsignin_div">
            <div id="gSignInWrapper">
                <div id="customBtn" class="customGPlusSignIn">
                  <span class="icon"></span>
                  <span class="buttonText">Sign in with Google</span>
                </div>
              </div>
              <script>startApp();</script>
        </div>

 var googleUser = {};
 var startApp = function() {
  gapi.load('auth2', function(){
  auth2 = gapi.auth2.init({
    client_id: '921258372597-t5jrb0e9p4ivstp9mfi972lhcvfcuo59.apps.googleusercontent.com',
    cookiepolicy: 'single_host_origin',
  });
  attachSignin(document.getElementById('customBtn'));
});
};

 function attachSignin(element) {
auth2.attachClickHandler(element, {},
    function(googleUser) {
          googleUser.getBasicProfile().getName();
                window.location.replace("http://localhost:30012/Duck/sign_/signin.html");
    }, function(error) {
      alert(JSON.stringify(error, undefined, 2));
    });
  }

正如用户成功登录后所见,用户被重定向到signin.html,但在那里我不知道处理oauth

用户重定向的网页代码:

 <!DOCTYPE html>

 <html>
 <head>
 <script src="oauthc_g_d.js"></script>
 <script>function attachSignin(element) {
          console.log(googleUser.getBasicProfile().getName());
 </script>

 </head>
 <body>
 <h1>Thanks for stopping by</h1>
 </body>
 </html>

这里我没有让控制台输出用户名

0 个答案:

没有答案