Mohit Prakash
Mohit Prakash

Reputation: 512

Google no longer supports authentication requests from the web view in ionin app

1) Added inappbrowser plugins 2) added googleplus plugins 3) installed ngcordova 4) install ng-cordova-oauth

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>

This code is for login by google in ionic app. but after this, i got a issue "Google no longer supports authentication requests from the web view. More information can be found at https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html.'

Please help me to solve this issue

Upvotes: 0

Views: 920

Answers (2)

Gopinath Kaliappan
Gopinath Kaliappan

Reputation: 7359

YES ,Google no longer supports authentication requests from the web view

Just try to make use of Native Oauth Process ,

Please See the link for better understanding

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

Upvotes: 0

Nat
Nat

Reputation: 310

Unfortunately, you have chosen to implement a soon-to-be-deprecated authentication mechanism for Google. Apr. 2017 is what I believe is the deprecation date, after which this method will not work, and it currently does not work for newer clients.

You will have to implement Google Auth login using the mechanism suggested at that website. Or you can use one of the plugins available, like onymos access.

Upvotes: 1

Related Questions