流星社交登录-使用Facebook或Google登录oauth2的空白页

问题描述:

我正在使用Meteor和Facebook或Google登录信息开发移动应用.

I am working on a mobile app using Meteor and Facebook or Google login.

在Android设备上效果很好.

On Android devices it works great.

但是在iOS设备上,成功通过身份验证后,我会得到一个空白页面.用户必须单击完成"按钮以关闭页面并获得应用程序的重新获得控制权.

But on iOS devices I get a blank page after successful authentication.The user has to click on a "Done" button to close the page and get the app regain control.

流星版本1.3.4.4和最新的accounts-facebookaccounts-google软件包.

Meteor version 1.3.4.4 and latest accounts-facebook, accounts-google packages.

这是我用于登录的代码:

This is the code I am using for login:

//Oauth login with Facebook.
this.loginFB = function() {
  Meteor.loginWithFacebook({
   requestPermissions: ['email', 'public_profile'],
   redirectUrl: Meteor.absoluteUrl('_oauth/facebook')
  }, function(err){
    if( err.error === 'Email exists.' ) {
      if (Meteor.isCordova) {

      } else {

      }
    }
  });
};

//Oauth login with Google.
this.loginGoogle = function() {
  Meteor.loginWithGoogle({
    requestPermissions: ['email', 'profile'],
    redirectUrl: Meteor.absoluteUrl('_oauth/google')
  }, function(err){
    if( err.error === 'Email exists.' ) {
      if (Meteor.isCordova) {

      } else {

      }
    }
  });
};

使用Meteor创建iOS混合应用程序时,后者使用Cordova和Cordova插件

When creating your iOS hybrid app using Meteor, the latter uses Cordova and the Cordova plugin InAppBrowser.

在展示第三方OAuth服务(Facebook,Google,GitHub或其他任何东西)时,很可能会使用该插件,从而很可能使新页面无法访问本地应用程序Cordova API.

That plugin is used when presenting the 3rd party OAuth service (whether Facebook, Google, GitHub or whatever), very probably so that the new page does not have access to the local app Cordova API.

不幸的是,在用于这种配置的插件中存在错误",请参见 [CB-11136] :

Unfortunately, there was a "bug" in that plugin when used in such a configuration, see [CB-11136]:

InAppBrowser无法使用WKWebView OAuth关闭

InAppBrowser fails to close with WKWebView OAuth

使用OAuth的WKWebView(例如Facebook或Google登录名)从Cordova iOS Platform 4+启动InAppBrowser失败.

Launching InAppBrowser from Cordova iOS Platform 4+ with its WKWebView for OAuth (e.g. Facebook or Google login) fails to close as it should.

原因是当提供另一个视图控制器时,整个WKWebView线程似乎暂停了.可以通过在Safari中检查WKWebView会话,运行window.open('http://something.com')并尝试在该Safari控制台中输入另一个命令来确认.

The reason is that the entire WKWebView thread seems to pause when another view controller is presented. This can be confirmed by inspecting the WKWebView session in Safari, running window.open('http://something.com') and then trying to enter another command into that Safari console.

这完全解释了为什么底层应用程序无法收回控制权并关闭该新窗口,但是当用户手动按下完成"按钮时一切正常,尤其是正确获取了访问令牌并且用户已登录到该应用程序).

This entirely explains why the underlying app cannot take control back and close that new window, but everything works fine when user manually presses the "DONE" button (in particular, access tokens are correctly retrieved and user gets logged in into the app).

此问题已在插件版本 1.7.0 .

This has been fixed as of plugin version 1.7.0.

手动将InAppBrowser插件版本升级到1.7.0或更高版本可解决所有已测试的OAuth登录服务在iOS Cordova打包应用程序上的问题:

Manually upgrading the InAppBrowser plugin version to 1.7.0 or later fixes the issue on iOS Cordova packaged apps for all tested OAuth login services:

meteor add cordova:cordova-plugin-inappbrowser@1.7.1

meteor add cordova:cordova-plugin-inappbrowser@1.7.1

(您可以浏览 Cordova插件注册表找到可用的最新版本)

(You can browse to the Cordova Plugins registry to find the latest available release)