我目前正在处理一个网络应用程序,该应用程序要求用户使用其Google帐户登录才能访问核心功能。使用Google Chrome浏览器时,所有功能都可以按预期的方式运行:用户单击“登录”,随即打开一个带有Google登录表单的弹出窗口,用户登录后,他将被转移到主页。(好的)
然而
使用Mozilla Firefox 38.0.1时,无法以任何方式使用该Web应用程序,因为当用户单击“登录”时,它不会执行任何操作。从字面上看,什么都没有,甚至在控制台上也没有错误。
这是登录按钮:
//head
<meta name="google-signin-client_id" content="{CLIENT ID}.apps.googleusercontent.com">
//body
<button class="g-signin2 login-button" data-onsuccess="onSignIn"></button>
Firefox和Google登录API是否存在当前已知的问题?
好的,找到了解决方案:我遵循了。基本上,我没有使用Google SignIn的轻松集成,而是创建了一个自定义处理程序和侦听器。我保留了原始按钮,因为它是必需的,并且只添加了以下javascript:
的HTML
<script src="https://apis.google.com/js/plus.js?onload=appStart"></script>
JS
//googleSignIn.js
var auth2; // The Sign-In object.
var googleUser; // The current user.
/**
* Calls startAuth after Sign in V2 finishes setting up.
*/
var appStart = function() {
console.log('appStart()')
gapi.load('auth2', initSigninV2);
};
/**
* Initializes Signin v2 and sets up listeners.
*/
var initSigninV2 = function() {
auth2 = gapi.auth2.getAuthInstance({
client_id: '{CLIENT ID}.apps.googleusercontent.com',
scope: 'profile'
});
// Listen for sign-in state changes.
auth2.isSignedIn.listen(signinChanged);
// Listen for changes to current user.
auth2.currentUser.listen(userChanged);
// Sign in the user if they are currently signed in.
if (auth2.isSignedIn.get() == true) {
auth2.signIn();
}
};
/**
* Listener method for sign-out live value.
*
* @param {boolean} val the updated signed out state.
*/
var signinChanged = function (val) {
console.log('Signin state changed to ', val);
};
/**
* Listener method for when the user changes.
*
* @param {GoogleUser} user the updated user.
*/
var userChanged = function (user) {
console.log('User now: ', user);
googleUser = user;
};
$('.login-button').on('click', function() {
console.log('signing in')
auth2.signIn().then(function(user) {
//callback to handle sign in
onSignIn(user);
});
})
我不确定是什么原因导致Google登录问题在mozilla上不起作用。如果有人知道这是已知问题,请在评论中让我知道。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句