Use refresh token if auth token expired in account authenticator Use refresh token if auth token expired in account authenticator android android

Use refresh token if auth token expired in account authenticator


You can save the refresh token into your account's user data when you first add your account using:

Bundle userdata = new Bundle;userdata.putString("refreshToken", refreshToken);mAccountManager.addAccountExplicitly (account, password, userdata);

You can also set the userdata after adding the account by calling:

mAccountManager.setUserData(account, "refreshToken", refreshToken);

When you access token is expired you can retrieve your refresh token by calling:

String refreshToken = mAccountManager.getUserData(account, "refreshToken");

Use the refreshToken to retrieve a new access token.