【问题标题】:Inappbrowser ionic doesn't load OauthInappbrowser ionic 不加载 Oauth
【发布时间】:2016-11-02 11:43:24
【问题描述】:

我正在使用 inappbrowser ionic 查看我的 webapp 的项目。我按照说明 (http://sourcefreeze.com/cordova-inappbrowser-plugin-example-using-ionic-framework/) 并在我的设备(iphone 6s、ios 10.1.1)上运行该应用程序。我的网络应用使用 google api,这里是服务

function GoogleDriveAuthentication($rootScope){

    this.authenticate = function(){
        gapi.load('client:auth2',authorize);
    }

    function authorize(){
        gapi.client.setApiKey($rootScope.API_KEY);
        gapi.auth2.init({
            client_id: $rootScope.CLIENT_ID,
            scope: $rootScope.SCOPES
        }).then(function(authResult){
            var auth2 = gapi.auth2.getAuthInstance();
            var user = auth2.currentUser.get();
            if (user.isSignedIn()) {
              afterSignInSuccess();
            } else {
              auth2.signIn().then(afterSignInSuccess,afterSignInFailed);
            }
        });
    }
    function afterSignInFailed(respond){
        console.log(respond);
    }

    function afterSignInSuccess(respond){
        console.log('authenticated successfully');
        var auth2 = gapi.auth2.getAuthInstance();
        var user = auth2.currentUser.get();
        var authResponse = user.getAuthResponse();
        $rootScope.accessToken = user.getAuthResponse().access_token;
        $rootScope.authenticated = true;
        gapi.client.load('drive', 'v3',function(){
            $rootScope.$broadcast('authenticated');
        });           
    }
}

这是我的 app.js 的一部分

app.run(function($rootScope,$location,$route, GoogleDriveAuthentication,DTOptionsBuilder){

$rootScope.$on('$routeChangeSuccess', function(){
    document.title = "SuperProject - " + $route.current.title;
    $('#superSearch').typeahead('val', '');
    if ($location.path() != "/register" && $location.path() != "/forgot"){
        if (!$rootScope.loggedin){
            console.log($rootScope.loggedin);
            $location.path("/login");
        } 
        else if (!$rootScope.authenticated){
            console.log('authenticate');
            GooghleDriveAuthentication.authenticate();
        }            
    }
    if ($location.path != '/home') {
        $('#superSearch').blur();
    }
})

And when I run it in Inappbrowser, it's stuck like this

我的科尔多瓦插件:

cordova-plugin-console 1.0.4 "Console"
cordova-plugin-device 1.1.3 "Device"
cordova-plugin-inappbrowser 1.5.0 "InAppBrowser"
cordova-plugin-splashscreen 4.0.0 "Splashscreen"
cordova-plugin-statusbar 2.2.0 "StatusBar"
cordova-plugin-whitelist 1.3.0 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"

在这种情况下,我可能会遇到我使用的 oauth2 v3 会在 Inappbrowser 中产生一些问题,我不确定。 知道我的应用有什么问题吗?任何帮助将不胜感激:)

【问题讨论】:

  • google 不再允许来自 inappbrowser 的 oauth
  • 有任何链接可以证明这一点吗,伙计?
  • 顺便说一句,我认为这是一个完全有效的问题。我相信你是第一个在这里发布它的人,因为新的凭据从 11 月起被阻止。 1 2016 年。不知道为什么它被标记为离题。

标签: cordova ionic-framework google-drive-api google-oauth inappbrowser


【解决方案1】:

Google 最近对此发出警告: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

出于安全原因,Google 不再允许使用 inAppBrowser 获取令牌。相反,使用cordova插件进行google登录,例如https://github.com/EddyVerbruggen/cordova-plugin-googleplus,它使用android原生方式。

作为奖励,您将获得与 Android 设备更好的集成:用户不再需要在首次使用时输入他们的电子邮件和密码。

某些应用仍然可以运行的原因是 Google 正在分阶段屏蔽。在控制台中创建的新身份验证凭据不再有效,但旧的凭据可以。在某些时候不会,请参阅上面的第一个链接。

【讨论】:

    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多