iainmcgin / AppAuth-Demo

A demonstration of using the AppAuth library with Google, Facebook, Microsoft and Github
Apache License 2.0
21 stars 6 forks source link

AppAuth Extended demo

WARNING: The demo app in this repository, while useful, does some very bad things that should not be copied for use in any production app. For further explanation, read the section on "Why is this app bad?" below.

This app demonstrate the use of the AppAuth for Android library to interact with four identity providers (IDPs): Facebook, GitHub, Google and Microsoft. While Google supports the current best-practices for OAuth2 from mobile devices (specifically, public clients and PKCE), the other providers do not:

This app registers for deep linking on Android M and above, and uses an interstitial page (see here) to capture the response on earlier versions of Android. The experience is far from perfect, but it does work.

Why is this app bad?

This app is a good example of what not to do when using AppAuth for Android:

DO NOT DO ANY OF THESE in your own apps. As things stand at the time of writing, one should not use AppAuth for Android to integrate directly with Facebook, GitHub or Microsoft. Once these providers support the recommendations of OAuth 2.0 for Native Apps then that will change.

What should I be doing instead?

For IDPs which rely on client secrets, all authorization should be performed with the support of your application's backend. In an ideal world, your application's backend itself would act as an OAuth2 or OpenID Connect authorization service: AppAuth would request authorization via your backend, which in turn would fan out to the IDP of the user's choice. The backend can then perform the exchange with the external IDP to secure a refresh token. When this succeeds, it can then create an authorization code to send to your app, which it exchanges for its own refresh token. All subsequent interaction with the external IDP would be mediated by your own backend.

This "ideal world" scenario is complex, and obviously requires that your app even has a backend / web app. It is our hope that as mobile applications become ever more important, identity providers will begin to support the recommendations that allow AppAuth to work as intended, with the client application fully in control of the authorization process.