Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic & Google OAuth for mobile app and web site

I am having trouble using the Google Plus authentication plugin in an Ionic app which talks to an API shared by our website.

In the Google Console I have three OAuth 2.0 client IDs, example ids given

  • Android client (auto created by Google Service) 1.apps.google
  • iOS client (auto created by Google Service) 2.apps.google
  • Webapp 3.app.googles

They all start with the same 12 digit number and end with "apps.googleusercontent.com".

According to Google's documentation I should be able to authenticate a mobile app and a website against the same API project by adding a scope setting that identifies the API's client id e.g. _scope:audience:server:client_id:3.apps.google_

this.googlePlus.login({
  'webClientId': '2.apps.google',
  'scope': 'scope:audience:server:client_id:3.apps.google'
})

I have been able to get a JWT returned from Google but when I decode it I find the aud value matches my webClientId setting when it should be the value from scope. As far as Ic an tell the only places that save the clientID persistently (as in not excluded by the .gitignore file that Ionic made) are config.xml

  <plugin name="cordova-plugin-googleplus" spec="git+https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git">
    <variable name="REVERSED_CLIENT_ID" value="google.apps.2" />
</plugin>

and package.json

  "cordova-plugin-googleplus": {
    "REVERSED_CLIENT_ID": "google.apps.2"
  }

So, which clients IDs do I put where so that my mobile app can authenticate users against the same API that our web site is using?

like image 748
Craig Avatar asked Dec 07 '17 23:12

Craig


People also ask

What is ionic used for?

Ionic provides a set of tools for building native iOS and Android applications, and mobile-ready Progressive Web Apps, using familiar web libraries, frameworks, and languages. Ionic Capacitor is a cross-platform native bridge that allows you to turn any web project into a native iOS or Android mobile application.

What is ionic and Electron?

For now lets just understand that, Ionic framework is a Hybrid Mobile application framework that let's us build mobile application with latest web technologies like HTML5, CSS and Javascript. And, Electron is Github's framework for developing cross-platform desktop application using same latest web technologies.

What language is ionic?

Quick Primer on Ionic Ionic apps are built using the languages of the web: HTML, CSS, and JavaScript. Thus, if you know how to build a basic web app, you already know how to build with Ionic. With Ionic, you can deploy a native iOS or Android app, native desktop app, or web app, all from a single, shared codebase.

What is an ionic component?

Ionic apps are made of high-level building blocks called components. Components allow you to quickly construct an interface for your app. Ionic comes with a number of components, including modals, popups, and cards. Check out the examples below to see what each component looks like and to learn how to use each one.


1 Answers

The solution seems to be a change in the API's client id. Until now we've been using the full id, like this

1234567890-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com

However, if we changed the API to use only the 1234567890 portion it accepted both the web and app clients, with of which are using their own IDs.

like image 157
Craig Avatar answered Oct 03 '22 03:10

Craig