Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I didn't know about using Google Play services for OAuth 2.0 authentication, but after taking a quick look at it, it looks pretty interesting and I think it's something I could prefer to use over the AccountManager.getAuthToken.</p> <h2>Major differences</h2> <p><strong><a href="http://developer.android.com/reference/android/accounts/AccountManager.html#getAuthToken%28android.accounts.Account,%20java.lang.String,%20android.os.Bundle,%20android.app.Activity,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler%29" rel="nofollow noreferrer">AccountManager.getAuthToken</a></strong></p> <p><strong>Pro:</strong></p> <ul> <li>Can be used for all Android 2.0 devices and newer.</li> <li>Is built in to Android and doesn't require any separate SDK.</li> <li>Can be used for all types of accounts that has an authenticator, not only Google.</li> </ul> <p><strong>Con:</strong></p> <ul> <li>Returns a token that may have expired so you always have to <a href="https://stackoverflow.com/questions/1996686/authtoken-from-accountmanager-in-android-client-no-longer-working">invalidate the token</a> and request it again to make sure you have a valid token.</li> <li>Requires the permissions GET_ACCOUNTS and USE_CREDENTIALS.</li> <li>Challenge screen is not user friendly for Android 2.*</li> </ul> <p><strong><a href="http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken%28android.content.Context,%20java.lang.String,%20java.lang.String%29" rel="nofollow noreferrer">GoogleAuthUtil.getToken</a></strong></p> <p><strong>Pro:</strong></p> <ul> <li>Always returns a <a href="http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken%28android.content.Context,%20java.lang.String,%20java.lang.String%29" rel="nofollow noreferrer">valid token</a>.</li> <li>Only <a href="http://developer.android.com/google/play-services/auth.html#choose" rel="nofollow noreferrer">requires</a> the permission GET_ACCOUNTS</li> <li>User friendly challenge screen.</li> <li><a href="https://stackoverflow.com/questions/14365219/in-a-nutshell-whats-the-difference-from-using-oauth2-request-getauthtoken-and-g#comment20015992_14374577">Recommended by Google</a></li> </ul> <p><strong>Con:</strong></p> <ul> <li>Require Android 2.2 and that the device have Google Play</li> <li>Require that you download and include the <a href="http://developer.android.com/google/play-services/setup.html" rel="nofollow noreferrer">Google Play services SDK</a> in your app.</li> <li>You need to <a href="http://android-developers.blogspot.se/2013/01/verifying-back-end-calls-from-android.html" rel="nofollow noreferrer">register your app</a> in the Google API Console</li> <li>Can "only" be used for Google services that uses OAuth 2.0</li> </ul> <h2>Challenge screen comparison</h2> <p><a href="http://developer.android.com/reference/android/accounts/AccountManager.html#getAuthToken%28android.accounts.Account,%20java.lang.String,%20android.os.Bundle,%20android.app.Activity,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler%29" rel="nofollow noreferrer">AccountManager.getAuthToken</a> Challenge screen on Gingerbread and Ice Cream Sandwich</p> <p><img src="https://i.stack.imgur.com/8n7OY.png" alt="getAuthToken challenge screen for Gingerbread"> <img src="https://i.stack.imgur.com/LWM5q.jpg" alt="getAuthToken challenge screen for Ice cream sandwich"></p> <p><a href="http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken%28android.content.Context,%20java.lang.String,%20java.lang.String%29" rel="nofollow noreferrer">GoogleAuthUtil.getToken</a> Challenge screen</p> <p><img src="https://i.stack.imgur.com/IEwcW.png" alt="getToken challenge screen"> <img src="https://i.stack.imgur.com/WTX4V.png" alt="getToken challenge screen, more details"></p> <h2>Summary</h2> <p>Since the GoogleAuthUtil approach has a much user friendlier challenge screen and requires less permissions at install time I would definitely use this approach instead of the AccountManager.getAuthToken approach whenever I can. Since you always get a valid token and don't have to hassle with invalidating the token it should make the code simpler as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload