【发布时间】:2019-01-09 06:32:21
【问题描述】:
我正在尝试在 cordova (phonegap) 应用中实现 Google Auth。
https://firebase.google.com/docs/auth/web/cordova?hl=en-419
- 我在 firebase xxxx.firebaseapp.com 中创建了一个身份验证域
- 我的应用在同一个应用中聚合到 firebase(我正在使用 firebase 进行分析)。
- 我已启用 Firebase 动态链接,并且可以查看我的域 xxxx.page.link
- 我已启用谷歌签名方法。
- 我已经安装了所有必需的插件
-
在我的 config.xml 中:
<universal-links> <host name="xxxx.page.link" scheme="https" /> <host name="xxxx.firebaseapp.com" scheme="https"> <path url="/__/auth/callback"/> </host> </universal-links> <preference name="AndroidLaunchMode" value="singleTask" />
我的登录方式:
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider).then(function() {
console.log("hola");
return firebase.auth().getRedirectResult();
}).then(function(result) {
// This gives you a Google Access Token.
// You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
afterLoginGoogle(user);
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log("error1 "+ errorMessage); //Error log!!!!
});
});
当我执行登录方法时,会启动一个新的 chrome 选项卡,并输入我的 google 用户名和密码。然后,关闭选项卡并再次显示应用程序,但我的控制台中总是出现错误: "error1 重定向操作在完成之前已被用户取消。"
我第一次收到此错误时,我在应用加载时输入了此代码:
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you a Google Access Token.
// You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
console.log("Despues");
afterLoginGoogle(user);
}
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log("Despues"+errorMessage);
});
我已尝试捕获所有动态链接事件进行测试,但未收到任何事件:
universalLinks.subscribe(null, function(eventData) {
alert('Did launch application from the link: ' + eventData.url);
});
但它永远不会运行:(
谁能帮帮我。我对这种情况感到筋疲力尽。
【问题讨论】:
标签: android cordova firebase oauth