Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google OAuth 2 on embedded Android-based device

We have an application for embedded Android-based device, it uses WebView and inside it we use Google OAuth 2 to login to the app. Unfortunately Google will soon block OAuth 2 inside WebView, and we have lots of restrictions:

  • The device doesn't have Google Services installed, so probably no 'official' way of logging in would work (or maybe any of them would work without Google Services?)
  • We can't just invoke Android browser to do login, because it shows address bar, which would allow the user to surf the internet, which we can't allow
  • We don't fully control the software installed on the device: can't install Google Services, update Android version, install Google Chrome, etc..., we can just update our app.

What else could we do having those restrictions?

like image 472
iirekm Avatar asked Mar 22 '17 09:03

iirekm


People also ask

What is OAuth2 in Android?

OAuth2 provides a single value, called an auth token, that represents both the user's identity and the application's authorization to act on the user's behalf.

What devices does Google oAuth support?

The Google OAuth 2.0 endpoint supports applications that are installed on devices such as computers, mobile devices, and tablets. When you create a client ID through the Google API Console, specify that this is an Installed application, then select Android, Chrome, iOS, or Other as the application type.

What OAuth protocol does Google API use?

Google APIs use the OAuth 2.0 protocol for authentication and authorization. Google supports common OAuth 2.0 scenarios such as those for web server, client-side, installed, and limited-input device applications. To begin, obtain OAuth 2.0 client credentials from the Google API Console.

What is OAuth2 in Android?

OAuth2 is a popular authorization framework that enables applications to protect resources from unauthorized access. AppAuth is an open source SDK for native Android and iOS apps.

How do I set up OAuth on Google Cloud Platform?

Google Cloud Platform Console Setting up OAuth 2.0 To use OAuth 2.0in your application, you need an OAuth 2.0 client ID, which your application uses when requesting an OAuth 2.0 access token. To create an OAuth 2.0 client ID in the console: Go to the Google Cloud Platform Console. From the projects list, select a project or create a new one.


1 Answers

Implementation through a browser:

1) Register custom URI scheme (How to implement my very own URI scheme on Android), for example, app-oauth2://

2) Make access request in user's browser

https://accounts.google.com/o/oauth2/v2/auth?
scope=...
access_type=offline&
include_granted_scopes=true&
state=state_parameter_passthrough_value&
redirect_uri=http://example.com/oauth2-handler&
response_type=code&
client_id=...

3) If user accept or denied requested rights in the confirmation dialog, it will be redirected to redirect_uri (http://example.com/oauth2-handler) with some params

4) On the side of redirect_uri handler (http://example.com/oauth2-handler), mare a redirect to custom URI scheme with params:

  • Success: app-oauth2://?state=state_parameter_passthrough_value&code=...&scope=...#
  • Failure: app-oauth2://?error=access_denied&state=state_parameter_passthrough_value#

5) In your app you can parse URI scheme app-oauth2:// from option 4 and receive the code for future usage or error for displaying to the user.

like image 127
cetver Avatar answered Oct 13 '22 09:10

cetver