Google 不再支持来自 ionin 应用中的网络视图的身份验证请求



1) 添加了应用程序浏览器插件2)添加了谷歌加插件3)安装恩科尔多瓦4)安装NG-科尔多瓦-奥特

angular.module('starter', ['ionic','ngCordova','ngCordovaOauth'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
.controller('WelcomeCtrl', function($scope, $state, UserService, $ionicLoading,$cordovaOauth) {
  $scope.googleSignIn = function() {
    
console.log('In My Method');
$cordovaOauth.google("here i am using my client id", ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function(result) {
    console.log(JSON.stringify(result));
}, function(error) {
    console.log('In Error');
    console.log(error);
});
  };
})
.service('UserService', function() {
  var setUser = function(user_data) {
    window.localStorage.starter_google_user = JSON.stringify(user_data);
  };
  var getUser = function(){
    return JSON.parse(window.localStorage.starter_google_user || '{}');
  };
  return {
    getUser: getUser,
    setUser: setUser
  };
});
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>
    <link rel="manifest" href="manifest.json">
    <!-- un-comment this code to enable service worker
    <script>
      if ('serviceWorker' in navigator) {
        navigator.serviceWorker.register('service-worker.js')
          .then(() => console.log('service worker installed'))
          .catch(err => console.log('Error', err));
      }
    </script>-->
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->
    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="js/ng-cordova.js"></script>
    <script src="js/ng-cordova-oauth.min.js"></script>
    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter" ng-controller="WelcomeCtrl">
    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <ion-content>
	  <a class="google-sign-in button button-block" ng-click="googleSignIn()">Sign in with Google</a>
      </ion-content>
    </ion-pane>
  </body>
</html>

此代码用于谷歌在 ionic 应用程序中登录。 但在此之后,我遇到了一个问题"谷歌不再支持来自 Web 视图的身份验证请求。 更多信息可以在 https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html 找到。

请帮我解决这个问题

很遗憾,您选择为 Google 实施即将弃用的身份验证机制。 我认为 2017 年 4 月是弃用日期,之后此方法将不起作用,并且目前不适用于新客户端。

您必须使用该网站上建议的机制实现Google身份验证登录。或者您可以使用可用的插件之一,例如 onymos 访问。

的,谷歌不再支持来自网页视图的身份验证请求

只是尝试使用本机Oauth进程,

请参阅链接以更好地理解

https://www.joshmorony.com/implementing-google-plus-sign-in-with-oauth-2-0-in-ionic-2/

最新更新