Accountmanager refresh token (offline access)

I use google login through account manager in my android application. I can get the accesstoken, which I send to the server, and the server can create / log in to a new user. Accesstoken is only valid 3600 seconds. The problem is that the server cannot update user information after this time. The web application requires periodic verification of user information.

How can I get the authentication token and update the token from the Android account manager so that the server can use the update token to periodically update the data? I do not want to use login via webview in android application.

thanks

+6
source share
3 answers

Now it's possible: https://developers.google.com/+/mobile/android/sign-in#server-side_access_for_your_app

You request a one-time authorization code, send it to your server, and your server exchanges it for an access token and updates the token.

+5
source

Currently you cannot, and I'm sure this is not the answer you are hoping for, sorry! If you have web login, you can use a hybrid stream to get the update token on the server (see https://developers.google.com/+/web/signin/server-side-flow ), but there is no way to get code as part of Android or iOS streams.

If this is what you need for your use, can you request a function request here: https://code.google.com/p/google-plus-platform/issues - we are actively looking at the number of stars to rate demand for various functions.

+3
source

Google authorization process through account manager:

Email ID can be obtained from

AccountManager accountManager = AccountManager.get(getApplicationContext()); Account[] accounts = accountManager.getAccountsByType("com.google"); String emailID = accounts[0].name; // you can retrieve using google account chooser way also 

These lines must be run in a separate token (not in the user interface thread).

 String scope = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://gdata.youtube.com"; String accessToken = GoogleAuthUtil.getToken(mContext, emailID, scope); 

save accessToken and use to access api.

After one hour (i.e. 3600 seconds), we need to update the access token. But now Google does not support access after an hour. We must restart the application and use the following lines to access the token.

 String scope = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://gdata.youtube.com"; String accessToken = GoogleAuthUtil.getToken(mContext, emailID, scope); 

This background thread will always run in the background during the loop.

0
source

All Articles