使用Auth2方法的Google身份验证过程在IE中不起作用

时间:2018-12-28 15:12:29

标签: internet-explorer internet-explorer-11 google-authentication

我们的网站允许我们的用户使用其Google凭据进行身份验证。由于Google API的某些更改,我不得不重写该过程。新方法适用于除IE之外的所有浏览器。有什么想法吗? IE不会出错,但是在身份验证窗口关闭后再也不会返回到侦听器。

<telerik:RadScriptBlock runat="server" ID="ctlGoogleScripts">

    <script type="text/javascript" src="https://apis.google.com/js/api.js" "></script>v
    <script type="text/javascript">
      var apiKey = 'our api key';
      var discoveryDocs = ["https://people.googleapis.com/$discovery/rest?version=v1"];
      var clientId = 'our client id';
      var scopes = 'profile';

      function handleClientLoad() {
        // Load the API client and auth2 library
          gapi.load('client:auth2', initClient);
       }

        function initClient() {
        gapi.client.init({
            apiKey: apiKey,
            discoveryDocs: discoveryDocs,
            clientId: clientId,
            scope: scopes,
            'immediate': false
        }).then(function () {
          // Listen for sign-in state changes.
          gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
        });
      }

      function updateSigninStatus(isSignedIn) {
        if (isSignedIn) {
                    makeApiCall();
        }
      }

      function handleAuthClick() {
        // here is my current issue, need to see if the user is signed in or not
        var isSignedIn = gapi.auth2.getAuthInstance().isSignedIn.get();
        if (isSignedIn) {
            makeApiCall();
        }
        else {
        gapi.auth2.getAuthInstance().signIn();
        }
      }

      function makeApiCall() {
        // Load the API and make an API call.  Display the results on the screen.
        gapi.client.people.people.get({ 
          'resourceName': 'people/me',
          'requestMask.includeField': 'person.emailAddresses'
        }).then(function(resp) {
          var email = resp.result.emailAddresses[0].value;
          //call server-side method to encrypt email and refresh page
          $.ajax({
            type: "POST",
            url: "our website address",
            data: "{'emailAddress': '" + email + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (retVal) {
                if (retVal.d !== '') {
                    window.location.href = retVal.d;
                }
            }   
          });
        });
      }
    </script>

    <script type="text/javascript" async defer src="https://apis.google.com/js/api.js" 
      onload="this.onload=function(){};handleClientLoad()" 
      onreadystatechange="if (this.readyState === 'complete') this.onload()">
    </script>

Google登录

0 个答案:

没有答案