Google Sign In for Web Apps not working with Inter

2019-01-22 03:33发布

问题:

Using the quick start sample provided by Google I've been able to get Sign In for Web Apps to work in Chrome and Firefox. However it fails on Internet Explorer (version 11.) It will log the user into Google but the data-onsuccess call back is never called. And there are typically no notifications of any errors.

I've read a related question and have tried the suggestions around Trusted Sites. I've also experimented with adjusting when IE accepts 3rd party cookies but none of this seems to work.

The code for the test page I'm using is below (minus the client-id)

<html>
<head>
<meta charset="ISO-8859-1">
<title>Google Sign In</title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="CLIENT_ID_FROM_GOOGLE_HERE">
<script>

function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    console.log('ID: ' + profile.getId());
    console.log('Name: ' + profile.getName());
    console.log('Image URL: ' + profile.getImageUrl());
    console.log('Email: ' + profile.getEmail());
}

function signOut() {
    console.log(document);

    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
        console.log('User signed out.');
    });
}
</script>
</head>

<body>
<h1>Login</h1>
<p>
This is a simple page to test Google Sign In IE
</p>

<div class="g-signin2" data-onsuccess="onSignIn">
   Sign In Button Rendered Here
</div>

<div>
    <a href="#" onclick="signOut();">Sign out</a>
</div>
</body>
</html>

I've also tried this with code that uses listeners to listen for changes, as suggested by some answers. I've had no success with that approach either. Again works in Chrome/Firefox but not in IE.

Every so often (not all the time) I do see a "SCRIPT5: Access is denied" error message in the Console. Not exactly sure why but I do notice that when the page is ultimately loaded some of the Google Code is in an <iframe> and I'm wondering if this is part of the problem.

I host the above test page on a local instance of Apache (running in Windows) and I'm wondering if there are cross domain issues perhaps with the code in the <iframe> coming from Google.

I'm at a complete loss at the minute and I'm eager to know if anyone has managed to get this to work with IE. Is there some configuration required to IE to allow this to work? Are there changes to the code needed to make it work? Or is it just essentially unworkable in IE?

An alternate that I can try is the server side flow however I'm not sure if this avoids the problem and ideally I'd like to use client side approach.

Any feedback is appreciated. Thank you.

Edit: I've hosted a simple page that illustrates the problem. This page works in Chrome, Firefox, and Safari. But fails when IE (v11) is used.

回答1:

The Google Identity team fixed this in November. If you are continuing to see issues on the JavaScript demo hosted at GitHub, please report and issue.

You can check the following demos to see the sample work on Edge/IE11:

  • Minimal Demo
  • Sample demo
  • Minimal Demo with insecure HTTP origin


回答2:

I used sign in and it worked for me ..

Here is my IE version :



回答3:

Try to load your scripts from other place than google. According to this Question (Preventing "SCRIPT5: Access is denied" error in IE) that "SCRIPT5: Access is denied. " error is a way Ms has to 'protect' the user against XSS.

So, try to download https://apis.google.com/js/platform.js and use it form your local server instead.



回答4:

Has there been any new ideas on this issue? I'm also seeing the same problem when trying to use the g-signin2 methods. I'm using the old s-gignin without issue right now across all browsers.

Oddly enough, this works for me on an IE10 browser, but not on IE11 or Edge



回答5:

While running in localhost, if you add Form Id to your form in Login page, it wont process after login through Google Login button. Even the Login status wont get changed to "Signed" on Google Login button. But this can be resolved by running the page on Public Server, since IE has feature to restrict scripts while running locally.