科尔多瓦Firebase Google Auth

Cur*_*las 2 android oauth cordova firebase

我正在尝试在cordova(phonegap)应用中实现Google Auth。

https://firebase.google.com/docs/auth/web/cordova?hl=zh-419

  • 我已经在Firebase xxxx.firebaseapp.com中创建了一个身份验证域
  • 我的应用程序聚合到同一应用程序中的Firebase(我正在使用Firebase进行分析)。
  • 我已启用Firebase动态链接,并且可以查看我的域xxxx.page.link
  • 我已启用Google Sign方法。
  • 我已经安装了所有必需的插件
  • 在我的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" />
    
    Run Code Online (Sandbox Code Playgroud)

我的登录方法:

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!!!!

            });
});
Run Code Online (Sandbox Code Playgroud)

当我执行登录方法时,将启动一个新的chrome标签,然后输入我的google用户名和密码。然后,关闭了选项卡,并再次显示了app,但是我总是在控制台中收到一个错误:“ 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);
    });
Run Code Online (Sandbox Code Playgroud)

我尝试捕获所有Dinamic链接事件进行测试,但未收到任何事件:

universalLinks.subscribe(null, function(eventData) {
            alert('Did launch application from the link: ' + eventData.url);
});
Run Code Online (Sandbox Code Playgroud)

但它永远不会运行:(

谁能帮我。我为这种情况感到高兴。

Cur*_*las 5

我将发布对自己问题的答案,因为它对其他人可能有用。

第一次,如果您按照指南https://firebase.google.com/docs/auth/web/cordova?hl=zh-419进行操作,它将可以正常工作。但...

科尔多瓦通用链接插件有一个问题,其中最新的科尔多瓦版本,尚未解决:https : //github.com/nordnet/cordova-universal-links-plugin/issues/133

您可以手动修复插件:在此文件中:./plugins/cordova-universal-links-plugin/hooks/lib/android/manifestWriter.js在第21行更改:

var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml');
Run Code Online (Sandbox Code Playgroud)

至:

var pathToManifest = path.join(
    cordovaContext.opts.projectRoot,
    'platforms',
    'android',
    'app',
    'src',
    'main',
    'AndroidManifest.xml');
Run Code Online (Sandbox Code Playgroud)

并且,如果您在使用通用链接时遇到问题,请查看清单结果文件:platform / android / app / src / main / AndroidManifest.xml

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:host="XXXXXXX.page.link" android:scheme="https"/>
  </intent-filter>
  <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:host="XXXXXXXXX.firebaseapp.com" android:scheme="https" android:path="/__/auth/callback"/>
  </intent-filter>
Run Code Online (Sandbox Code Playgroud)

并检查此配置是否等同于您的config.xml。您不得更改清单文件!!!仅用于检查。如果不是,请检查config.xml中是否有多个有关通用链接的注释。